Skip to content

Commit f632dcd

Browse files
authored
Merge pull request serverless#64 from tmilewski/patch-1
Lock down permissions to a specific table
2 parents c70cc0d + 054f9d8 commit f632dcd

File tree

6 files changed

+9
-8
lines changed

6 files changed

+9
-8
lines changed

aws-node-rest-api-with-dynamodb/serverless.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ frameworkVersion: ">=1.1.0 <2.0.0"
55
provider:
66
name: aws
77
runtime: nodejs4.3
8+
environment:
9+
DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}
810
iamRoleStatements:
911
- Effect: Allow
1012
Action:
11-
- dynamodb:DescribeTable
1213
- dynamodb:Query
1314
- dynamodb:Scan
1415
- dynamodb:GetItem
1516
- dynamodb:PutItem
1617
- dynamodb:UpdateItem
1718
- dynamodb:DeleteItem
18-
Resource: "arn:aws:dynamodb:us-east-1:*:*"
19+
Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/${env:DYNAMODB_TABLE}"
1920

2021
functions:
2122
create:
@@ -75,4 +76,4 @@ resources:
7576
ProvisionedThroughput:
7677
ReadCapacityUnits: 1
7778
WriteCapacityUnits: 1
78-
TableName: 'todos'
79+
TableName: ${env:DYNAMODB_TABLE}

aws-node-rest-api-with-dynamodb/todos/create.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports.create = (event, context, callback) => {
1515
}
1616

1717
const params = {
18-
TableName: 'todos',
18+
TableName: process.env.DYNAMODB_TABLE,
1919
Item: {
2020
id: uuid.v1(),
2121
text: data.text,

aws-node-rest-api-with-dynamodb/todos/delete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const dynamoDb = new AWS.DynamoDB.DocumentClient();
66

77
module.exports.delete = (event, context, callback) => {
88
const params = {
9-
TableName: 'todos',
9+
TableName: process.env.DYNAMODB_TABLE,
1010
Key: {
1111
id: event.pathParameters.id,
1212
},

aws-node-rest-api-with-dynamodb/todos/get.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const dynamoDb = new AWS.DynamoDB.DocumentClient();
66

77
module.exports.get = (event, context, callback) => {
88
const params = {
9-
TableName: 'todos',
9+
TableName: process.env.DYNAMODB_TABLE,
1010
Key: {
1111
id: event.pathParameters.id,
1212
},

aws-node-rest-api-with-dynamodb/todos/list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const AWS = require('aws-sdk');
44

55
const dynamoDb = new AWS.DynamoDB.DocumentClient();
66
const params = {
7-
TableName: 'todos',
7+
TableName: process.env.DYNAMODB_TABLE,
88
};
99

1010
module.exports.list = (event, context, callback) => {

aws-node-rest-api-with-dynamodb/todos/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports.update = (event, context, callback) => {
1616
}
1717

1818
const params = {
19-
TableName: 'todos',
19+
TableName: process.env.DYNAMODB_TABLE,
2020
Key: {
2121
id: event.pathParameters.id,
2222
},

0 commit comments

Comments
 (0)