Create a session to prepare to store conversation history and context - Amazon Bedrock
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

Create a session to prepare to store conversation history and context

To create a session, you use the CreateSession API operation. In the response, Amazon Bedrock returns a unique session ID and Amazon Resource Name (ARN) for the session. You use either the session ID or the ARN when you use the CreateInvocation and PutInvocationStep API operations to record the session events.

When you create a session, you can specify a AWS KMS key to encrypt conversations. For information about encryption, see Session encryption.

def create_session(): try: session_id = client.create_session( encryptionKeyArn="arn:aws:kms:us-west-2:<123456789012>:key/keyId", tags={ 'Environment': 'Test', 'Project': 'Demo' }, sessionMetadata={ "deviceType": "mobile" } )["sessionId"] print("Session created. Session ID: " + session_id) return session_id except ClientError as e: print(f"Error: {e}")