AppStream env variable for session-context contains last session's context during startup script - bug or feature?

0

We are seeing what I would like to describe as a bug in AppStream, allthoug the expected behaviour is just based on intuition, and not really documented.

Problem Description

When running the start script in AppStream, the environment variable APPSTREAM_SESSION_CONTEXT contains the session-context specified for the previous session (same user, same fleet), not the current session.

If I for example run (Session #1)

aws appstream create-streaming-url --stack-name my-stack --fleet-name my-fleet --user-id 10 --application-id notepad --session-context CONTEXT-A

And have a start script including this line:

Write-Output "CONTEXT=$($env:APPSTREAM_SESSION_CONTEXT)"

It will print

CONTEXT=

Now, if I expire that session and start a new (Session #2) using

aws appstream create-streaming-url --stack-name my-stack --fleet-name my-fleet --user-id 10 --application-id notepad --session-context CONTEXT-B

It will print (with an A and not the expected B)

CONTEXT=CONTEXT-A

This is only the case in the shell of the start script, not in a shell later opened by the user. In a shell opened by the user, the "correct" (the specified) context is set. That is, in the Session #1$env:APPSTREAM_SESSION_CONTEXT=CONTEXT-A and in the Session #2 $env:APPSTREAM_SESSION_CONTEXT=CONTEXT-B.

My setup

I connect to the AppStream instance using a Browser.

Start script

Setup:

With start script I mean the executable specified in SessionStart of the config.json file:

{
  "SessionStart": {
    "executables": [
      {
        "context": "user",
        "filename": "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe",
        "arguments": "-NonInteractive -File C:\\Scripts\\start_script.ps1",
        "s3LogEnabled": true
      }
    ],
    "waitingTime": 60
  }
}

Start script itself (Powershell)

$StartDate = (Get-Date).ToUniversalTime()
$AppStreamImgArn = $env:AppStream_Image_Arn
$SessionID = (Get-Item Env:AppStream_Session_ID).Value
$AS2UserName = (Get-Item Env:AppStream_UserName).Value
$AS2StackName = (Get-Item Env:AppStream_Stack_Name).Value
$AS2FleetName = (Get-Item Env:AppStream_Resource_Name).Value

Write-Output "User $AS2UserName starting session $SessionID in $AS2StackName/$AS2FleetName at $((Get-Date).ToUniversalTime())"
Write-Output "ImageArn: $AppStreamImgArn"
Write-Output "CONTEXT=$($env:APPSTREAM_SESSION_CONTEXT)"

Stack

  MyStack:
    Type: AWS::AppStream::Stack
    Properties:
      Name: my-stack
      StorageConnectors:
        - ConnectorType: 'HOMEFOLDERS'
          ResourceIdentifier: 'MyIdentifier'
      ApplicationSettings:
        Enabled: true
        SettingsGroup: AStack
      EmbedHostDomains:
        - !Ref EmbedHostDomain
      RedirectURL: !Ref RedirectURL

Fleet

  MyFleet:
    Type: AWS::AppStream::Fleet
    Properties:
      Name: my-fleet
      DisplayName: My Fleet
      InstanceType: stream.graphics-design.large
      FleetType: ON_DEMAND
      StreamView: APP
      ComputeCapacity:
        DesiredInstances: 1
      VpcConfig:
        SubnetIds: !ImportValue
              'Fn::Sub': '${NetworkStackName}-PrivateSubnet1'
        SecurityGroupIds:
          - !ImportValue
            'Fn::Sub': '${NetworkStackName}-NoIngressSecurityGroup'
      MaxUserDurationInSeconds: 345600
      DisconnectTimeoutInSeconds: 7200
      IdleDisconnectTimeoutInSeconds: 0 # Disabled
      EnableDefaultInternetAccess: False
      IamRoleArn: !GetAtt AppStreamFleetRole.Arn
      ImageArn: arn:aws:appstream:eu-west-1::image/AppStream-Graphics-Design-WinServer2019-03-24-2024
Andreax
asked 13 days ago60 views
1 Answer
2
Accepted Answer

Hello Andreax,

The session script is executed before the APPSTREAM_SESSION_CONTEXT variable is created and set. The APPSTREAM_SESSION_CONTEXT is available after the first application launch. See documentation.  

So when you run it first time (Session #1) with argument as Context A the output is blank because the variable is not available/created yet. When you run it in second session (Session #2) with argument as Context B, it shows value from previous session because you would have application setting persistence enabled so it saved it in the profile from previous session. In the 2nd session, since the start script is executed before the variable is set you see old value and not new value. But if you check it again in the second session you will see correct value.

Regards Mayank

AWS
answered 13 days ago
profile picture
EXPERT
reviewed 13 days ago
  • Thanks for a quick answer with good links!

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