This project was created to demonstrate how to create a REST API using AWS SAM and deploying using carlin.
- Install:
yarn
- Create the base stack:
yarn run create-base-stack
- Deploy:
yarn run deploy
- If you want to destroy the stack:
yarn run deploy --destroy
This example has three endpoints:
- GET /print: return
{ event, context }
in whichevent
andcontext
are Lambda arguments. - GET /now/dayjs: return the current date returned by Day.js.
- GET /now/moment: return the current date returned by Moment.js.
An overview of the deploy algorithm:
src/lambda.ts
is bundled in a single file by Webpack and zipped.- The zip file is uploaded to a S3 bucket created by base stack.
- Deploy
src/cloudformation.yml
. carlin pass the S3 bucket parameters to template automatically.
Moment.js was chosen because its size. The bundled file has 690 kB and, the zipped file, 116.3 kB.
It took about 79 seconds the whole deployment process.
You may want to use Lambda layers to ignore some packages when Webpack are going to bundle the Lambda code. To do so, carlin provides the command carlin deploy lambda-layer
that automates the layers deployment. At the end, it returns the ARN and some exported name for each layer that can be added to the CloudFormation template:
Layers:
- !ImportValue CarlinLambdaLayerDayjs1dot9dot7
- !ImportValue CarlinLambdaLayerMoment2dot29dot1
Now, the bundled file has 4.9 kB and, the zipped file, 1.5 kB.