Michael Wolfenden
04/05/2021, 10:23 PMconst table = /* table stack */
const api = new sst.Api(this, 'Api', {
routes: {
'GET /restaurants': {
handler: `src/functions/get-restaurants.main`,
environment: {
RESTAURANTS_TABLE_NAME: table.dynamodbTable.tableName,
},
},
},
})
I want to give that particular route only scan access to dynamodb.
Is the code below correct or do I need to use to specify a complete IAM policy
api.attachPermissionsToRoute('GET /restaurants', [table, 'dynamodb:Scan'])
Also is it possible to specify permissions in-line with the route definition?Frank
dynamodb:*
to this table
• dynamodb:Scan - this grants dynamodb:Scan
to all tables
api.attachPermissionsToRoute('GET /restaurants', [table, 'dynamodb:Scan'])
Frank
dynamodb:Scan
to all tables:
api.attachPermissionsToRoute('GET /restaurants', ['dynamodb:Scan'])
Frank
dynamodb:Scan
to just a specific table:
api.attachPermissionsToRoute('GET /restaurants', [
new iam.PolicyStatement({
actions: ["dynamodb:Scan"],
effect: iam.Effect.ALLOW,
resources: [ table.tableArn ],
}),
])
Michael Wolfenden
04/05/2021, 11:19 PMFrank
Frank
Michael Wolfenden
04/05/2021, 11:25 PMFrank
Michael Wolfenden
04/05/2021, 11:28 PMFrank
permissions
inline in v0.10.11. You can also configure permission
inside defaultFunctionProps
. And the default permissions will be merged with the route permissions if both are configured for a given route.
Here are a couple of examples -
https://docs.serverless-stack.com/constructs/Api#specifying-function-props-for-all-the-routesMichael Wolfenden
04/14/2021, 10:18 AM