By using AWS re:Post, you agree to the Terms of Use

Appstream Elastic Fleet set Environment Variables in Windows


I have an application set up as an Elastic Fleet in AppStream2. I want to set up some environment variables for that application on a per user basis, ideally associated with a user from the User Pool, and not associated with a directory account.

The environment variables will contain connection string settings for a database, as well as a user id for the application.

Is this possible?

asked 3 months ago51 views
1 Answer

Setting Windows environment variables is pretty straightforward - you can write a script that calls Windows commands to set them (SET/SETX for batch/cmd, $env or [System.Environment]::SetEnvironmentVariable for Powershell).

What's a bit more complicated is getting the value to be set to that environment variable. When using the CreateStreamingURL API or SAML2.0 federation, you can use the SessionContext parameter to pass information into the streaming instance which AppStream 2.0 then sets as the AppStream_Session_Context environment variable. User Pools does not support this capability, and isn't recommended for use beyond proof of concepts - it's not meant to be an identity provider. Instead, the recommendation is to integrate your existing identity provider to eliminate the need of managing users/passwords within AppStream 2.0

For all authentication modes, AppStream 2.0 also creates the fleet and instance metadata environment variables which you can use on your scripts to get information about the user and the fleet. One way to manage a per-user connection string would be to have a lookup (perhaps through a Lambda function) based the username that's streaming, and return the connection string for them, to be set as the Windows environment variable. Alternatively, if you only have a handful of users, and the information isn't sensitive (eg: no issue if other users see it), store and set the values using a session script that executes before the user session starts.

Hope this helps.

answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions