Skip to main content

AWS Sam

Commands

sam build
sam deploy [--guided]

sam delete
  • Create pipeline: cd aws-lab && sam pipeline init --bootstrap
  • Validate SAM template: cd aws-lab && sam validate
  • Test Function in the Cloud: cd aws-lab && sam sync --stack-name {stack-name} --watch

Get start with SAM

Deploy first times

Lambda in hello-word folder:

Add follow-paris-lambda-1 folder lambda

Add FollowParisLambda1 resource in template.yaml file:

# ...
FollowParisLambda1:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: follow-paris-lambda-1/
Handler: app.lambdaHandler
Runtime: nodejs20.x
Architectures:
- x86_64
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /lambda-1
Method: get
Metadata: # Manage esbuild properties
BuildMethod: esbuild
BuildProperties:
Minify: true
Target: es2020
Sourcemap: true
EntryPoints:
- app.ts
# ...

Create follow-paris-lambda-1 project, and run npm init to init project.

{
...,
"devDependencies": {
"@types/aws-lambda": "^8.10.134",
"@types/node": "^20.11.24",
"typescript": "^5.3.3"
},
"dependencies": {
"esbuild": "^0.20.1"
}
}

Deploy second times

Add First Python Lambda

Add FollowParisLambdaConverHtmlToPdf resource in template.yaml file:

Resources:
# ...
FollowParisLambdaConverHtmlToPdf:
# ...
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: python-follow-paris-lambda-convert-html-to-pdf/
Handler: app.lambda_handler
Runtime: python3.9
Architectures:
- x86_64
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /lambda-convert-html-to-pdf
Method: get
# ...

Create python-follow-paris-lambda-convert-html-to-pdf folder.

Deploy

Question

Resources