Goal: Each function has a dedicated IAM role and therefore minimise attack surface
Install serverless-iam-roles-per-function plugin
- Install
serverless-iam-roles-per-functionas dev dependency
npm install --save-dev serverless-iam-roles-per-function
- Modify
serverless.ymland add it as a plugin
Update the plugins section so it looks like this:
plugins:
- serverless-pseudo-parameters
- serverless-iam-roles-per-functionIssue individual permissions
-
Modify
serverless.ymland delete theiamRoleStatementssection -
Modify
serverless.ymland give theget-restaurantsfunction its own IAM role statements
IMPORTANT: make sure this iamRoleStatements is aligned with environment and events
iamRoleStatements:
- Effect: Allow
Action: dynamodb:scan
Resource:
Fn::GetAtt:
- restaurantsTable
- Arn- Modify
serverless.ymland give thesearch-restaurantsfunction its own IAM role statements
iamRoleStatements:
- Effect: Allow
Action: dynamodb:scan
Resource:
Fn::GetAtt:
- restaurantsTable
- Arn- Modify
serverless.ymland give theplace-orderfunction its own IAM role statements
iamRoleStatements:
- Effect: Allow
Action: kinesis:PutRecord
Resource:
Fn::GetAtt:
- orderEventsStream
- Arn- Modify
serverless.ymland give thenotify-restaurantfunction its own IAM role statements
iamRoleStatements:
- Effect: Allow
Action: kinesis:PutRecord
Resource:
Fn::GetAtt:
- orderEventsStream
- Arn
- Effect: Allow
Action: sns:Publish
Resource:
Ref: restaurantNotificationTopic- Deploy the project
npm run sls -- deploy
- Run the acceptance tests to make sure they're still working
STAGE=dev REGION=eu-west-1 npm run acceptance