0
0
AWScloud~20 mins

Serverless Application Model (SAM) in AWS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SAM Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Architecture
intermediate
2:00remaining
Understanding AWS SAM Template Structure

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: get
AAn Amazon DynamoDB table with a primary key
BAn Amazon SNS topic for messaging
CAn Amazon S3 bucket configured for static website hosting
DAn AWS Lambda function triggered by an API Gateway HTTP GET request
Attempts:
2 left
💡 Hint

Look at the Type and Events sections to identify the resource.

service_behavior
intermediate
2:00remaining
SAM Deployment Behavior with CodeUri

When deploying an AWS SAM application, what happens if the CodeUri property points to a local directory?

ASAM packages the local code directory into a deployment artifact and uploads it to an S3 bucket automatically
BSAM directly uploads the local directory contents to the Lambda function without packaging
CSAM requires the user to manually upload the code to S3 before deployment
DSAM ignores the <code>CodeUri</code> and deploys an empty Lambda function
Attempts:
2 left
💡 Hint

Think about how SAM handles local code during deployment.

security
advanced
2:30remaining
IAM Role Configuration in SAM

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/MyTable
AThe policy allows all DynamoDB actions on all tables in the account
BThe policy allows GetItem on all DynamoDB tables in the region
CThe policy allows only the GetItem action on the specified DynamoDB table resource
DThe policy denies all DynamoDB actions on the specified table
Attempts:
2 left
💡 Hint

Check the Action and Resource fields carefully.

Configuration
advanced
2:30remaining
SAM Template Environment Variables Configuration

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: debug
AEnvironment variables must be set outside the Properties section
BThe environment variables STAGE and LOG_LEVEL are correctly set for the Lambda function
CThe environment variables are incorrectly nested and will cause a deployment error
DSAM does not support environment variables in Lambda functions
Attempts:
2 left
💡 Hint

Review the correct placement of environment variables in SAM templates.

Best Practice
expert
3:00remaining
Optimizing SAM Template for Multiple Environments

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?

AUse one SAM template with parameterized values and pass environment-specific parameters during deployment
BUse separate SAM templates for each environment with duplicated resources and values
CHardcode all environment values in the SAM template and manually edit before each deployment
DDeploy the SAM application once and manually change configuration in the AWS Console for each environment
Attempts:
2 left
💡 Hint

Think about maintainability and automation when managing multiple environments.