From c9106c58fbd6fb2205aa94de433d1e047f5035e4 Mon Sep 17 00:00:00 2001 From: Richard Wright Date: Mon, 26 Sep 2022 17:17:09 +0100 Subject: [PATCH 1/2] feat: update serverless and code to fix dynamodb local connection issues --- .../serverless.yml | 14 ++++++++------ .../todos/dynamodb.js | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/aws-node-rest-api-with-dynamodb-and-offline/serverless.yml b/aws-node-rest-api-with-dynamodb-and-offline/serverless.yml index 14995c42c..85d94c9e5 100644 --- a/aws-node-rest-api-with-dynamodb-and-offline/serverless.yml +++ b/aws-node-rest-api-with-dynamodb-and-offline/serverless.yml @@ -14,16 +14,18 @@ custom: port: 8000 inMemory: true migrate: true - # Comment if you don't have a DynamoDB running locally - noStart: true + # Comment if you don't have a DynamoDB running locally + #noStart: true migration: dir: offline/migrations provider: name: aws runtime: nodejs12.x + region: eu-west-1 + stage: dev environment: - DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage} + DYNAMODB_TABLE: ${self:service}-${sls:stage} iam: role: statements: @@ -35,8 +37,8 @@ provider: - dynamodb:PutItem - dynamodb:UpdateItem - dynamodb:DeleteItem - Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}" - + Resource: "arn:aws:dynamodb:${aws:region}:*:table/${self:provider.environment.DYNAMODB_TABLE}" + functions: create: handler: todos/create.create @@ -61,7 +63,7 @@ functions: path: todos/{id} method: get cors: true - + update: handler: todos/update.update events: diff --git a/aws-node-rest-api-with-dynamodb-and-offline/todos/dynamodb.js b/aws-node-rest-api-with-dynamodb-and-offline/todos/dynamodb.js index 2a08ba9c4..bbf79ace9 100644 --- a/aws-node-rest-api-with-dynamodb-and-offline/todos/dynamodb.js +++ b/aws-node-rest-api-with-dynamodb-and-offline/todos/dynamodb.js @@ -9,6 +9,8 @@ if (process.env.IS_OFFLINE) { options = { region: 'localhost', endpoint: 'http://localhost:8000', + accessKeyId: 'DEFAULT_ACCESS_KEY', // needed if you don't have aws credentials at all in env + secretAccessKey: 'DEFAULT_SECRET' // needed if you don't have aws credentials at all in env }; } From a5e3571f8df45cf4dbdb19bc4ccacc05f6811ac3 Mon Sep 17 00:00:00 2001 From: Richard Wright Date: Mon, 3 Oct 2022 14:48:37 +0100 Subject: [PATCH 2/2] chore: fix formatting --- aws-node-rest-api-with-dynamodb-and-offline/serverless.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-node-rest-api-with-dynamodb-and-offline/serverless.yml b/aws-node-rest-api-with-dynamodb-and-offline/serverless.yml index 85d94c9e5..bbee446b6 100644 --- a/aws-node-rest-api-with-dynamodb-and-offline/serverless.yml +++ b/aws-node-rest-api-with-dynamodb-and-offline/serverless.yml @@ -63,7 +63,7 @@ functions: path: todos/{id} method: get cors: true - + update: handler: todos/update.update events: