Serverless applications - AWS Lambda
To read:
https://aws.amazon.com/lambda/
https://docs.aws.amazon.com/lambda/latest/dg/welcome.html
To read and test examples:
https://docs.aws.amazon.com/lambda/latest/dg/getting-started.html
Configure region for AWS CLI
aws configure
AWS Access Key ID [****************????]: <Enter>
AWS Secret Access Key [****************????]:<Enter>
Default region name [None]: us-east-1
Default output format [None]: <Enter>
AWS CLI commands for AWS Lambda
List lambda functions
aws lambda list-functions
Invoke lambda function
aws lambda invoke --function-name my-function out
To include the invocation log, provided as a separate LogResult attribute:
aws lambda invoke --function-name my-function out --log-type Tail
To extract LogResult (which is encoded in Base64) and decode it:
aws lambda invoke --function-name my-function out --log-type Tail --query
'LogResult' --output text | base64 -d
Invoke lambda function with parameters
aws lambda invoke --function-name my-function --payload '{ "key": "value" }'
out
Invoke lambda function asynchronous
aws lambda invoke --function-name my-function --invocation-type Event out
Get lambda function content
aws lambda get-function --function-name my-function
// the URL for the function content is provided in Location attribute
Delete lambda function
aws lambda delete-function --function-name my-function
// also don’t forget to delete the role created for this function and its attached policy (go to Services /
Identity and Access Management (IAM) / Roles | Policies)
Assignment
Create a lambda function that takes as parameter a JSON object that provides the first name and last
name of a person and responds with a greeting.
You have to set the permission to use the LabRole role.
Example:
JSON object: {firstName: ' John', lastName:' Doe'}
Response: Hello John Doe!
Assignment 2
Test the Tutorial: Using an Amazon S3 trigger to invoke a Lambda function from https://
docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html