- You need the serverless framework installed globally
npm install -g serverless
- Set your AWS credentials as environment variables using Isengard
Run this before deploying or testing locally
npm install
sls invoke local --function api --path events/event.json
Every time you call deploy, it changes an environment variable force it to redeploy each time. To disable comment out the following line in serverless.yml
:
DEPLOYMENT_ID: Deployment-${sls:instanceId}
to comment use #
at the beginning of the line
sls deploy
To switch between layer and esbuild
- Comment out the layer in
serverless.yml
#layers: # - !Sub 'arn:aws:lambda:${AWS::Region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:21'
- Comment out the exclude section in
serverless.yml
The code autodetects whether it is using a layer or not and sets a#exclude: #- '@aws-lambda-powertools' #- 'aws-xray-sdk-core'
isLayer
flag in the log, tracer annotation and metrics metadata. - Redeploy
The code imports the metrics, tracer and logger libraries and instantiates them. It creates an sts client and wraps it with the tracer. In the handler it calls getCallerIdentity to return some info to the caller and uses the metrics, tracer and logger libraries. Code
If you don't want to manually deploy and look at the traces and logs, there are tools to help. The SDK blog post on reducing cold start times uses a modified version of this code for the benchmarking: https://github.com/lumigo-io/SAR-measure-cold-start It will change environment variables to force a cold start and invoke the function multiple times and report the results.