Given the following AWS SAM template snippet, what resource type is being defined?
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs14.x
CodeUri: ./src
Events:
ApiEvent:
Type: Api
Properties:
Path: /hello
Method: getLook at the Type and Events sections to identify the resource.
The resource type AWS::Serverless::Function defines a Lambda function. The Events section shows it is triggered by an API Gateway event on the GET method at path /hello.
When deploying an AWS SAM application, what happens if the CodeUri property points to a local directory?
Think about how SAM handles local code during deployment.
SAM automatically packages the local code directory specified in CodeUri into a zip file and uploads it to an S3 bucket during deployment.
In an AWS SAM template, if you want to restrict a Lambda function's permissions to only read items from a specific DynamoDB table, which of the following IAM policy snippets correctly achieves this?
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action: dynamodb:GetItem
Resource: arn:aws:dynamodb:us-east-1:123456789012:table/MyTableCheck the Action and Resource fields carefully.
The policy explicitly allows only the dynamodb:GetItem action on the specified table ARN, restricting permissions as intended.
Which of the following SAM template snippets correctly sets environment variables for a Lambda function?
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Handler: app.lambda_handler
Runtime: python3.9
Environment:
Variables:
STAGE: prod
LOG_LEVEL: debugReview the correct placement of environment variables in SAM templates.
Environment variables are set under Properties.Environment.Variables in the SAM template, as shown, which is correct.
You want to deploy the same SAM application to multiple environments (dev, test, prod) with different configuration values like memory size and environment variables. Which approach follows best practices?
Think about maintainability and automation when managing multiple environments.
Using parameters in a single SAM template allows you to reuse the template and pass different values per environment, which is a best practice for maintainability and automation.