Complete the code to define a serverless function using AWS Lambda.
def handler(event, context): return [1]
The Lambda function should return a string as the response. Returning a string like "Hello from Lambda!" is correct.
Complete the code to create an AWS Lambda function trigger from an API Gateway event.
def handler(event, context): if event["httpMethod"] == [1]: return {"statusCode": 200, "body": "Success"}
The API Gateway event includes the HTTP method in the "httpMethod" key. To handle a GET request, the value should be "GET".
Fix the error in the AWS SAM template to define a Lambda function resource.
Resources:
MyFunction:
Type: [1]
Properties:
Handler: index.handler
Runtime: python3.9
CodeUri: ./src/In AWS SAM templates, Lambda functions are defined with the type "AWS::Serverless::Function" to enable serverless features.
Fill both blanks to configure an AWS Lambda function with environment variables and memory size.
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
MemorySize: [1]
Environment:
Variables:
STAGE: [2]The MemorySize property expects an integer value like 512 (MB). Environment variables are strings, so "dev" is a valid stage name.
Fill all three blanks to create a serverless function with an S3 trigger and proper permissions.
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.9
Events:
S3Event:
Type: S3
Properties:
Bucket: [1]
Events: [2]
Policies:
- [3]The S3 event trigger requires the bucket name as a string, the event type as "s3:ObjectCreated:*", and the policy to allow read access is "AmazonS3ReadOnlyAccess".