Skip to content

Commit 7c743bf

Browse files
- update AWSSDK to support secrets manager
- integrate middy's secretsManager middleware
1 parent 2d20d51 commit 7c743bf

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

functions/get-index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const cloudwatch = require('../lib/cloudwatch');
1212
const AWSXRay = require('aws-xray-sdk');
1313

1414
const middy = require('middy');
15-
const { ssm } = require('middy/middlewares');
15+
const { ssm, secretsManager } = require('middy/middlewares');
1616
const sampleLogging = require('../middleware/sample-logging');
1717
const captureCorrelationIds = require('../middleware/capture-correlation-ids');
1818

@@ -89,8 +89,8 @@ const handler = co.wrap(function* (event, context, callback) {
8989
dayOfWeek,
9090
restaurants,
9191
awsRegion,
92-
cognitoUserPoolId: context.cognito_user_pool_id,
93-
cognitoClientId: context.cognito_client_id,
92+
cognitoUserPoolId: context.cognito.user_pool_id,
93+
cognitoClientId: context.cognito.client_id,
9494
searchUrl: `${context.restaurants_api}/search`,
9595
placeOrderUrl: `${context.orders_api}`
9696
};
@@ -119,8 +119,13 @@ module.exports.handler = middy(handler)
119119
setToContext: true,
120120
names: {
121121
restaurants_api: `/bigmouth/${STAGE}/restaurants_api`,
122-
orders_api: `/bigmouth/${STAGE}/orders_api`,
123-
cognito_user_pool_id: `/bigmouth/${STAGE}/cognito_user_pool_id`,
124-
cognito_client_id: `/bigmouth/${STAGE}/cognito_client_id`
122+
orders_api: `/bigmouth/${STAGE}/orders_api`
123+
}
124+
}))
125+
.use(secretsManager({
126+
cache: true,
127+
cacheExpiryInMillis: 3 * 60 * 1000, // 3 mins
128+
secrets: {
129+
cognito: `/bigmouth/${STAGE}/cognito`
125130
}
126131
}));

package-lock.json

Lines changed: 13 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"superagent-promise": "^1.1.0"
2121
},
2222
"devDependencies": {
23-
"aws-sdk": "^2.168.0",
23+
"aws-sdk": "^2.302.0",
2424
"chai": "^4.1.2",
2525
"cheerio": "^1.0.0-rc.2",
2626
"lodash": "^4.17.10",

serverless.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ functions:
5050
- Effect: Allow
5151
Action: ssm:GetParameters*
5252
Resource: arn:aws:ssm:#{AWS::Region}:#{AWS::AccountId}:parameter/bigmouth/${self:custom.stage}/*
53+
- Effect: Allow
54+
Action: secretsmanager:GetSecretValue
55+
Resource: arn:aws:secretsmanager:#{AWS::Region}:#{AWS::AccountId}:secret:/bigmouth/${self:custom.stage}/*
5356

5457
get-restaurants:
5558
handler: functions/get-restaurants.handler

0 commit comments

Comments
 (0)