From 835f9d83293a7d4934c0a347c279493626c87ade Mon Sep 17 00:00:00 2001 From: Andy Hayden Date: Tue, 14 Jan 2020 23:07:10 -0800 Subject: [PATCH] Update serverless example to use SAR application --- .gitignore | 1 + example/README.md | 25 +++++++++---------------- example/client.ts | 1 + example/package-lock.json | 21 --------------------- example/serverless.yml | 21 +++++++++++---------- 5 files changed, 22 insertions(+), 47 deletions(-) delete mode 100644 example/package-lock.json diff --git a/.gitignore b/.gitignore index b53efe8e..6e5382f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .deno_dir .serverless node_modules +package-lock.json *.zip \ No newline at end of file diff --git a/example/README.md b/example/README.md index 25dd3de9..33757add 100644 --- a/example/README.md +++ b/example/README.md @@ -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/). diff --git a/example/client.ts b/example/client.ts index 6a8dfab1..e29a6720 100644 --- a/example/client.ts +++ b/example/client.ts @@ -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 }; diff --git a/example/package-lock.json b/example/package-lock.json deleted file mode 100644 index da461cc0..00000000 --- a/example/package-lock.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "requires": true, - "lockfileVersion": 1, - "dependencies": { - "bluebird": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.1.tgz", - "integrity": "sha512-DdmyoGCleJnkbp3nkbxTLJ18rjDsE4yCggEwKNXkeV123sPNfOCYeDoeuOY+F2FrSjO1YXcTU+dsy96KMy+gcg==", - "dev": true - }, - "serverless-scriptable-plugin": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/serverless-scriptable-plugin/-/serverless-scriptable-plugin-1.0.4.tgz", - "integrity": "sha512-bQQ2iY1GbZlDndXnnCN7TWunLN4tjIv0u3PXueW00bxpzFCBqag8UkDN+nUCls9qK9yaaiuV3zpAp7wiq5qOIA==", - "dev": true, - "requires": { - "bluebird": "3.7.1" - } - } - } -} diff --git a/example/serverless.yml b/example/serverless.yml index e5466186..318525ed 100644 --- a/example/serverless.yml +++ b/example/serverless.yml @@ -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 @@ -34,7 +27,7 @@ functions: candidateSubmission: handler: api/candidate.submit layers: - - { Ref: DenoLambdaLayer } + - !GetAtt Deno.Outputs.DenoArn memorySize: 128 description: Submit candidate info events: @@ -45,7 +38,7 @@ functions: listCandidates: handler: api/candidate.list layers: - - { Ref: DenoLambdaLayer } + - !GetAtt Deno.Outputs.DenoArn memorySize: 128 description: List all candidates events: @@ -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: @@ -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: