Question

Difficulty: EasyServerless Development with AWS Lambda

A developer is deploying a new AWS Lambda function that must write log data to an Amazon DynamoDB table. To keep the code reusable across multiple environments (such as staging and production), the developer must avoid hardcoding the DynamoDB table name. Additionally, the Lambda function must be authorized to write data to the DynamoDB table. Which two configurations should the developer use to meet these requirements? (Select two.)

  1. Configure environment variables for the function to dynamically specify the DynamoDB table name.Answer
  2. Assign an IAM execution role to the Lambda function that contains permissions to write to the DynamoDB table.Answer
  3. C
    Store the DynamoDB table name and AWS access keys directly within the function's code initialization.
  4. D
    Attach an IAM trust policy to the Lambda function that permits the DynamoDB service to assume the function's role.
  5. E
    Deploy the Lambda function inside a private subnet and configure a security group to block outbound internet traffic.

Answer

To configure the function correctly, configure environment variables for the DynamoDB table name and assign an IAM execution role to the function with DynamoDB write permissions.
To dynamically change the target table name across different stages without redeploying code, the developer must use environment variables. To grant write permissions to the DynamoDB table, the developer must assign an IAM execution role to the Lambda function containing the correct policy permissions.

Step-by-Step Solution

1
Determine how to pass configuration metadata like table names dynamically to the function code.
Use Lambda environment variables to pass the DynamoDB table name, avoiding code changes when moving between staging and production environments.
This complies with serverless development best practices of separation of configuration from code.
2
Determine the mechanism to authorize the Lambda function to execute operations on DynamoDB.
Create an IAM role containing DynamoDB write permissions and configure it as the Lambda function's execution role.
Lambda requires an execution role to perform API calls against other AWS resources under its execution context.

Key Concept

Lambda Environment Variables and IAM Execution Roles
Rate this question