Build, Test and Deploy

  1. Create SAM template
  2. Build
  3. Test
  4. Deploy
AWSTemplateFormatVersion: '2016-10-31'
Transform: AWS::Serverless-2016-10-31
Description:
AWS Lambda SAM Build, deploy , test locally
Resources:
AWSSAMLambdaFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: LambdaCode/
Handler: app.lambda_handler
Runtime: python3.9
Timeout: 75
FunctionName: AWSSAMtest
MemorySize:512
Events:
CreateFileEvent:
Type: S3
Properties:
Bucket: !Ref SrcBucket
Events: s3:ObjectCreated:*
SrcBucket:
Type: AWS::S3::Bucket
# using the SAM command you can generate certain AWS resource event locally and test Lambda locallysam local generate-event s3 [put/delete] --help# Below command automatically generate the put and delete event locally and pass it to Lambda.py code for testing purposes.sam local generate-event s3 [put/delete] --bucket <bucketname> --key <prefixname> | sam local invoke -e - <sample SAM function lambda.py >
# browse to the folder and start the Lambda
sam local start-lambda [OPTIONS]
#publish the local lambda app to HTTP url
aws lambda invoke --function-name "SAMTestApp" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl out.txt
$ sam build
$ sam deploy 
# or
$ sam-deploy --guided

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store