A developer is using AWS Serverless Application Model (SAM) to deploy a database-backed API. The database password is saved as a SecureString in AWS Systems Manager Parameter Store. The developer attempts to reference this password in the SAM template's `Parameters` section as follows:
yaml
Parameters:
DbPassword:
Type: AWS::SSM::Parameter::Value<String>
Default: /prod/db/password
During the `sam deploy` process, AWS CloudFormation returns a validation error indicating that `AWS::SSM::Parameter::Value<String>` cannot reference SSM SecureString parameters.
How should the developer resolve this deployment failure while keeping the database password secure?
- Remove the parameter from the template's `Parameters` section and reference it directly in the function's environment variables using the `{{resolve:ssm-secure:/prod/db/password}}` dynamic reference.Answer
- BUpdate the parameter's `Type` to `AWS::SSM::Parameter::Value<SecureString>` in the `Parameters` section to support secure SSM parameters.
- CAdd a new `Transform` statement specifically within the `Parameters` section of the template to compile the secure parameter values.
- DModify the execution role's trust policy in the template to allow the `ssm.amazonaws.com` service principal to assume the role.
Answer
Remove the parameter from the template's `Parameters` section and reference it directly in the function's environment variables using the `{{resolve:ssm-secure:/prod/db/password}}` dynamic reference.
AWS CloudFormation parameters cannot resolve SSM SecureString parameters when using the `AWS::SSM::Parameter::Value<String>` type. To secure and dynamically retrieve sensitive configuration data from Parameter Store, developers must use dynamic references. By removing the parameter from the template's `Parameters` section and referencing `{{resolve:ssm-secure:/prod/db/password}}` directly within the resource properties (e.g., inside the environment variables of the function), the secure value is retrieved securely at deployment time without validation errors.
Step-by-Step Solution
Key Concept
AWS SAM Integration with Systems Manager Parameter Store Secure Strings