Connecting AWS Lambda functions to AWS Systems Manager Cloud Extensions
Connect your AWS Lambda functions to a Cloud Extensions profile, and verify, update, and remove the connection.
You connect a Lambda function to Cloud Extensions in two parts. First, you add the Cloud Extensions runtime to the function as a layer. Second, you point the function to a profile. The profile stores the extensions that the function loads, and the settings of the extensions. You can point a function to a profile with the Lambda console or the AWS CLI.
Topics
How Lambda integration works
You point a function to a profile by setting the AWS_CLOUDEXTENSIONS_PROFILE environment variable of the function to the name or ID of the profile. The runtime loads that profile.
When the function runs, the Cloud Extensions runtime starts in the execution environment. The runtime retrieves the profile, compares the SHA-256 hash of each extension with the hash in the profile state, and loads the extensions. Each execution environment runs its own runtime with its own cache.
Because the environment variable holds the profile name or ID, you can change which extensions a function uses by pointing it to a different profile. You don't change your function code.
Connecting a function on the console
To connect a function to a profile on the Lambda console
-
Open the Lambda console, and then choose your function.
-
Choose the Configuration tab, and then choose Environment variables.
-
Choose Edit, and then choose Add environment variable.
-
For Key, enter
AWS_CLOUDEXTENSIONS_PROFILE. For Value, enter the name or ID of your profile. -
Choose Save.
The role of the function needs the cloudextensions:SyncState action. For the policy, see Permissions for the runtime.
Connecting a function with the AWS CLI
To connect a function to a profile with the AWS CLI, run the update-function-configuration command. Replace with the name of your function, and replace function-name with the name of your profile:profile-name
aws lambda update-function-configuration \ --function-namefunction-name\ --environment "Variables={AWS_CLOUDEXTENSIONS_PROFILE=profile-name}"
The --environment option of the update-function-configuration command replaces the whole map of environment variables. To keep your existing variables, include them in the command, together with AWS_CLOUDEXTENSIONS_PROFILE.
Verifying the connection
To verify the connection, invoke the function and check that the extensions are active. The runtime writes its startup and extension messages to the logs of the function. For the messages, see Runtime logs.
If the extensions don't load as expected, see Troubleshooting AWS Systems Manager Cloud Extensions.
Updating and removing the connection
To point a function to a different profile, change the value of the AWS_CLOUDEXTENSIONS_PROFILE environment variable to the name or ID of the new profile. To remove Cloud Extensions from a function, remove the layer and delete the environment variable. For more information, see Stopping the use of Cloud Extensions.
When you update a profile, the runtime applies the change in the first invocation after the 45 seconds pass. A new execution environment loads the current profile when it starts. You don't need to change the function. For more information, see Working with AWS Systems Manager Cloud Extensions profiles.
Considerations
Review the following considerations when you connect functions to Cloud Extensions:
-
Functions that already use other Lambda layers or extensions can also use Cloud Extensions.
-
When you combine many extensions in a profile, consider the memory and the startup time of the execution environment.
-
The time that an execution environment spends frozen counts toward the cache time to live of an extension.