Skip to content

Creating a REST API using AWS Serverless and deploy by Carlin

Notifications You must be signed in to change notification settings

ttoss/poc-aws-serverless-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

POC - AWS Serverless REST API

This project was created to demonstrate how to create a REST API using AWS SAM and deploying using carlin.

Creating the API

  1. Install:
yarn
  1. Create the base stack:
yarn run create-base-stack
  1. Deploy:
yarn run deploy
  1. If you want to destroy the stack:
yarn run deploy --destroy

API

This example has three endpoints:

  • GET /print: return { event, context } in which event and context 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.

Carlin

An overview of the deploy algorithm:

  1. src/lambda.ts is bundled in a single file by Webpack and zipped.
  2. The zip file is uploaded to a S3 bucket created by base stack.
  3. Deploy src/cloudformation.yml. carlin pass the S3 bucket parameters to template automatically.

Results

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.

carlin deploy command

Adding Lambda Layers

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.

About

Creating a REST API using AWS Serverless and deploy by Carlin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published