Skip to content

AWS Lambda examples | go python typescript | SAM serverless aws-cli terraform

Notifications You must be signed in to change notification settings

vzsoares/lambda-kitchen

Repository files navigation

Lambda Kitchen

what's cooking? lambdas!

Available Lambdas/Layers

see at lambdas folder

lambdas/
├── go-microservice-handlers-terraform
├── go-monolithic-http-terraform
├── typescript-handler-awscli
├── typescript-layer-serverless
├── typescript-microservice-handlers-sam
├── typescript-monolithic-express-sam
└── typescript-monolithic-proxy-serverless

Requirements:

  • make
  • aws
  • sam
  • terraform
  • go
  • node
  • yarn

Usage:

yarn install

yarn nx -- <command>

###

# shows workspace graph
yarn nx -- graph

# show project individual commands
cd lambdas/<project> && make help

Useful stuff:

Use one bucket for all lambdas

by default serverless/sam creates one bucket for each lambda, and thats a problem because the account bucket limit is 100 by default

Api gateway custom domain

serverless:

plugin: serverless-domain-manager

post

to stage path e.g www.domain/`dev`/images

Configure serverless-domain-manager config basePath to '${sls:stage}/'

Environment variables:

serverless:

The best way is to use aws SSM, see also

And follow this pattern in serverless.yml:

    MY_VAR: ${ssm:/${sls:stage}/MY_VAR}

note the sls:stage, witch guarantees staging note that ssm var work like paths so they always start with a forward slash (/)

other:
  • Add the vars after deploy with a script

or

  • Use the cdk for iam/secrets manager

Disable cloudwatch/Manage permissions

Do this to cut costs

Theres no cli option or config to that, but the best workaround is to manipulate permissions.

You either just disallow the cloudwatch or only allow lambda creation.

You could create a aws role or declare the policie directly on the yaml example:

#only allow functions
iam:
  role:
    statements:
      - Effect: 'Allow'
        Action:
          - 'lambda:InvokeFunction'
        Resource: '*'

Policie to disallow cloudwatch Serverless iam docs

Links

Other Examples: