CodexBloom - Programming Q&A Platform

AWS CloudFormation scenarios to Update Lambda Environment Variables with SSM Parameters

šŸ‘€ Views: 1586 šŸ’¬ Answers: 1 šŸ“… Created: 2025-06-12
aws cloudformation lambda ssm parameters YAML

I'm not sure how to approach I'm working with an scenario with AWS CloudFormation where updates to my Lambda function's environment variables are not reflecting after I change the linked SSM parameters... I have a CloudFormation template that defines a Lambda function and pulls environment variables from AWS Systems Manager Parameter Store using the following snippet: ```yaml Resources: MyLambdaFunction: Type: 'AWS::Lambda::Function' Properties: FunctionName: MyFunction Role: !GetAtt MyLambdaExecutionRole.Arn Handler: index.handler Runtime: nodejs14.x Environment: DATABASE_URL: '{{resolve:ssm:/myapp/databaseurl}}' Code: S3Bucket: mybucket S3Key: myfunction.zip ``` Initially, this configuration worked perfectly, and the Lambda function was able to access the `DATABASE_URL` from SSM. However, when I updated the value of the SSM parameter and then deployed the updated CloudFormation stack, the Lambda function did not pick up the new value. Instead, it still uses the old value from before the update. I've tried adding the `UpdateReplacePolicy` to the Lambda resource, but it didn't seem to help. The CloudFormation stack updates successfully without any errors, but the environment variable remains unchanged. I also verified that the SSM parameter's value was updated correctly and that the IAM role associated with the Lambda function has permission to access the SSM parameters. The stack events show that the Lambda function was updated, but the environment variable value does not reflect the change. Is there something I’m missing in the CloudFormation template or best practices regarding SSM parameters and Lambda? Any insights or suggestions would be greatly appreciated! Any help would be greatly appreciated! I'm on Windows 11 using the latest version of Yaml. Could someone point me to the right documentation?