A developer is deploying a serverless application using AWS SAM. The developer needs to deploy a Lambda function that retrieves a database credential from AWS Secrets Manager. The developer writes the following template (`template.yaml`):
yaml
Resources:
DBSecret:
Type: AWS::SecretsManager::Secret
Properties:
Name: my-db-secret
SecretString: '{"password":"mypassword"}'
RetrieveSecretFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs18.x
CodeUri: ./src
Policies:
- AWSSecretsManagerGetSecretValuePolicy:
SecretArn: !Ref DBSecret
Environment:
Variables:
SECRET_NAME: !Ref DBSecret
When attempting to deploy this template using the AWS CLI `aws cloudformation deploy` command, the deployment fails with the error: `Template format error: Unrecognized resource type: AWS::Serverless::Function`. Additionally, the Lambda function code is incorrectly configured to retrieve the database credential using the Systems Manager Parameter Store SDK API client.
Which two actions must the developer take to resolve the deployment failure and ensure the Lambda function can retrieve the database credential?
- Add the `Transform: AWS::Serverless-2016-10-31` declaration at the root level of the template.Cevap
- Modify the Lambda function code to use the AWS Secrets Manager API client (such as calling `GetSecretValue`) to retrieve the credential.Cevap
- CAdd a trust relationship policy to the Lambda execution role that explicitly trusts the Secrets Manager service principal (`secretsmanager.amazonaws.com`).
- DUse the Systems Manager Parameter Store client in the Lambda function code, as Secrets Manager automatically replicates all credentials to Parameter Store by default.
- EReplace the `AWS::Serverless::Function` resource type with `AWS::Lambda::Function` and remove the `CodeUri` property.