Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vzsoares/lambda-kitchen

Lambda examples
https://github.com/vzsoares/lambda-kitchen

aws-lambda examples

Last synced: about 1 month ago
JSON representation

Lambda examples

Awesome Lists containing this project

README

        

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:

```sh

yarn install

yarn nx --

###

# shows workspace graph
yarn nx -- graph

# show project individual commands
cd lambdas/ && 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

- [plugin: serverless-deployment-bucket](https://www.serverless.com/plugins/serverless-deployment-bucket)

- [samconfig](https://github.com/aws/aws-sam-cli/blob/develop/designs/sam-config.md)

### Api gateway custom domain

##### serverless:

[plugin: serverless-domain-manager](https://www.serverless.com/plugins/serverless-domain-manager)

[post](https://www.serverless.com/blog/serverless-api-gateway-domain/)

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](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html), [see also](https://www.serverless.com/framework/docs/providers/aws/guide/variables#reference-variables-using-the-ssm-parameter-store)

And follow this pattern in serverless.yml:

```yaml
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:

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

[Policie to disallow cloudwatch](https://stackoverflow.com/questions/51166504/disable-cloudwatch-to-monitor-logs-for-lambda-function)
[Serverless iam docs](https://www.serverless.com/framework/docs/providers/aws/guide/iam)

## Links

- organize lambdas: https://aws.amazon.com/blogs/compute/best-practices-for-organizing-larger-serverless-applications/

- typescript power-tools: https://aws.amazon.com/blogs/compute/simplifying-serverless-best-practices-with-aws-lambda-powertools-for-typescript/

- memory optimization: https://theburningmonk.com/2020/03/how-to-optimize-lambda-memory-size-during-ci-cd-pipeline/
https://medium.com/geekculture/pick-the-right-memory-size-for-your-aws-lambda-functions-682394aa4b21

## Other Examples:

- monolithic go https://github.com/build-on-aws/golang-apis-on-aws-lambda
- microservice go https://github.com/aws-samples/serverless-go-demo
- monolithic typescript https://github.com/rodrigokamada/nodejs-aws-lambda