JwtTokenRotatorFunction Lambda Function

The JwtTokenRotatorFunction Lambda function generates a JSON Web Token (JWT) and stores it in AWS Secrets Manager so that Amazon Connect can authenticate its connection to Salesforce to support real-time streaming for Agentforce Voice on Amazon Connect.

If Salesforce manages your Amazon Connect instance, this Lambda function is deployed automatically when you update your contact center to version 22.1 or later. If you manage your own Amazon Connect instance, perform these steps to deploy the Lambda function and generate a valid token.

  1. Deploy this Lambda function using the SalesforceJwtRotatorNonScvStack.yaml CloudFormation stack. The JwtTokenRotatorScheduledRule Amazon EventBridge rule triggers this function every 55 minutes. The function uses the environment variables in Table 1, which are set at deployment time.
  2. Open the configuration secret in AWS Secrets Manager and replace the placeholder value in the <identity>-scrt-jwt-auth-private-key field with your RSA private key. The function can’t generate a valid token until you complete this step.

This function runs automatically and requires no manual invocation or contact-flow configuration. On each scheduled trigger, the function reads the Salesforce Org ID, identity name (Call Center or Messaging Channel API name), and RSA private key from the configuration secret. It then signs a new JWT with a 60-minute validity period and a unique token ID, and writes it to the JWT secret, overwriting the previous value.

Amazon Connect reads the JWT secret at call time and presents the token as a bearer token in the Authorization header of its WebSocket upgrade request to Salesforce.

For multiorg deployments, pass SECRET_NAME and JWT_SECRET_NAME as input parameters instead of setting them as environment variables. This allows a single Lambda to serve multiple call centers. See Table 2 for the corresponding input attributes.

VariableDescription
SECRET_NAMEName of the secret that stores your Salesforce org details and private key.
JWT_SECRET_NAMEName of the secret where the generated JWT is stored.
INCLUDE_ROLES_CLAIMWhen set to true, includes a voice agent role in the token. Required when you manage your own Amazon Connect instance.
LOG_LEVELSets the detail level for the Lambda function logs.
AttributeDescription
secretNameOverrides SECRET_NAME for this invocation. Used in multiorg deployments.
jwtSecretNameOverrides JWT_SECRET_NAME for this invocation. Used in multiorg deployments.
AttributeDescription
statusCodeReturns 200 on success.
messageReturns JWT token rotated successfully on success. On failure, the function returns an error and the existing token doesn’t change.