It’s been a while since I’ve written any notes about the Serverless framework, so here’s a few notes as a refresher on typical steps I use for local development.
As a reminder to self, regions I typically deploy to are:
AWS Lambdas can be packaged and deployed using a Docker image, described in the docs here.
Serverless Framework makes building and deploying a Docker based Lambda incredibly simple. If you have a simplest Dockerfile like this (from the docs here):
FROM public.ecr.aws/lambda/nodejs:14
# Assumes your function is named "app.js", and there is a package.json file in the app directory
COPY app.js package.json ${LAMBDA_TASK_ROOT}
# Install NPM dependencies for function
RUN npm install
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "app.handler" ]
The handler to be packaged in this image is this simplest hello world function:
To define a Lambda using this image, with Serverless define an ECR section like this to define your image, which will get built using the above Dockerfile in the same folder:
serverless deploy : deploys the whole stack (but if nothing has changed there is no update)
serverless deploy function -f functioname: updates just the code on that one Lambda (and updates in a couple of seconds vs several seconds for updating the whole stack).