Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Update serverless example to use SAR application
Browse files Browse the repository at this point in the history
  • Loading branch information
hayd committed Jan 15, 2020
1 parent fef4a9f commit 835f9d8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.deno_dir
.serverless
node_modules
package-lock.json
*.zip
25 changes: 9 additions & 16 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@

Deploy in a single step using [`serverless deploy`](https://serverless.com/framework/docs/providers/aws/guide/deploying/).

This example lambda application defines:
This example lambda application defines in `serverless.yml`:

- A lambda layer from the `deno-lambda-layer.zip`.
- A DynamodDB table "candidates".
- Three lambda functions a list/get/submit.
- Three lambda functions list/get/submit in `api/candidate.ts`.
- An API Gateway endpoint to these functions.

Requires `deno-lambda-layer.zip` to be in the directory:
Note: The `serverless-scriptable-plugin` is used to compile `api/candidate.ts` prior to upload
so there is no init-time download/compilation step.

curl -sfL https://github.com/hayd/deno-lambda/releases/download/v0.4.0/deno-lambda-layer.zip -o deno-lambda-layer.zip

This example is based on [_Building a REST API in Node.js with AWS Lambda, API Gateway, DynamoDB, and Serverless Framework_ blogpost by Shekhar Gulat](https://serverless.com/blog/node-rest-api-with-serverless-lambda-and-dynamodb/).

See the application described in `serverless.yml` and the exported functions in `api/candidate.ts`.

Note: The `serverless-scriptable-plugin` is used to compile `api/candidate.ts` so there is no init-time download/compilation step.
```sh
# Install serverless-scriptable-plugin:
npm install --save-dev serverless-scriptable-plugin
```

---

TODO:

- [ ] Should layer be a distinct template/directory? Each full deploy pushes a new version of the layer, ideally this shouldn't be the case.
https://serverless.com/blog/publish-aws-lambda-layers-serverless-framework/ ?
- [ ] Tests are included, require local-dynamodb to be running. Should be part of CI.
This example is based on [_Building a REST API in Node.js with AWS Lambda, API Gateway, DynamoDB, and Serverless Framework_ blogpost by Shekhar Gulat](https://serverless.com/blog/node-rest-api-with-serverless-lambda-and-dynamodb/).
1 change: 1 addition & 0 deletions example/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DynamoDBClient, createClient } from "./deps.ts";
const conf = {
accessKeyId: Deno.env("AWS_ACCESS_KEY_ID"),
secretAccessKey: Deno.env("AWS_SECRET_ACCESS_KEY"),
sessionToken: () => Deno.env("AWS_SESSION_TOKEN"),
region: Deno.env("AWS_REGION") || "local",
port: Deno.env("AWS_REGION") ? 443 : 8000
};
Expand Down
21 changes: 0 additions & 21 deletions example/package-lock.json

This file was deleted.

21 changes: 11 additions & 10 deletions example/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ provider:
Resource:
- Fn::GetAtt: [candidatesTable, Arn]

layers:
deno:
description: "deno"
package:
artifact: deno-lambda-layer.zip
# TODO extract this out so we don't redeploy the layer on each push.

package:
exclude:
- .deno_dir/gen/file
Expand All @@ -34,7 +27,7 @@ functions:
candidateSubmission:
handler: api/candidate.submit
layers:
- { Ref: DenoLambdaLayer }
- !GetAtt Deno.Outputs.DenoArn
memorySize: 128
description: Submit candidate info
events:
Expand All @@ -45,7 +38,7 @@ functions:
listCandidates:
handler: api/candidate.list
layers:
- { Ref: DenoLambdaLayer }
- !GetAtt Deno.Outputs.DenoArn
memorySize: 128
description: List all candidates
events:
Expand All @@ -56,7 +49,7 @@ functions:
candidateDetails:
handler: api/candidate.get
layers:
- { Ref: DenoLambdaLayer }
- !GetAtt Deno.Outputs.DenoArn
memorySize: 128
description: Get candidate by id
events:
Expand All @@ -65,7 +58,15 @@ functions:
method: get

resources:
Transform: AWS::Serverless-2016-10-31
Resources:
Deno:
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:390065572566:applications/Deno
SemanticVersion: 0.7.0

candidatesTable:
Type: AWS::DynamoDB::Table
Properties:
Expand Down

0 comments on commit 835f9d8

Please sign in to comment.