Last active
February 20, 2023 16:51
-
-
Save phstc/af34bb8fd091820e300f513a4aeffbef to your computer and use it in GitHub Desktop.
Retool DDB integration + AWS CDK IAM User and Policy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://docs.retool.com/docs/dynamodb-integration | |
import { Stack, StackProps } from "aws-cdk-lib"; | |
import * as dynamodb from "aws-cdk-lib/aws-dynamodb"; | |
import * as iam from "aws-cdk-lib/aws-iam"; | |
import { Construct } from "constructs"; | |
export class DataStack extends Stack { | |
public readonly table: dynamodb.Table; | |
constructor(scope: Construct, id: string, props?: StackProps) { | |
super(scope, id, props); | |
const table = new dynamodb.Table(this, 'table', { | |
partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING }, | |
sortKey: { name: 'sk', type: dynamodb.AttributeType.STRING }, | |
}); | |
table.addGlobalSecondaryIndex({ | |
indexName: 'gsi1', | |
partitionKey: { name: 'gsipk1', type: dynamodb.AttributeType.STRING }, | |
sortKey: { name: 'gsisk1', type: dynamodb.AttributeType.STRING }, | |
}) | |
this.table = table; | |
// https://docs.retool.com/docs/dynamodb-integration | |
const retoolUser = new iam.User(this, 'retool-dynmoadb'); | |
/* | |
retoolUser.addToPolicy(new iam.PolicyStatement({ | |
actions: [ | |
"dynamodb:DeleteItem", | |
"dynamodb:GetItem", | |
"dynamodb:BatchGetItem", | |
"dynamodb:BatchWriteItem", | |
"dynamodb:PutItem", | |
"dynamodb:Scan", | |
"dynamodb:Query", | |
"dynamodb:UpdateItem", | |
"dynamodb:GetRecords", | |
"dynamodb:GetShardIterator" | |
], | |
resources: [ | |
table.tableArn, | |
`${table.tableArn}/index/*` | |
], | |
})) | |
*/ | |
table.grantReadWriteData(retoolUser) | |
retoolUser.addToPolicy(new iam.PolicyStatement({ | |
actions: [ | |
"dynamodb:ListTables", | |
"dynamodb:ListTagsOfResource", | |
"dynamodb:DescribeReservedCapacityOfferings", | |
"dynamodb:DescribeTable", | |
"dynamodb:DescribeContinuousBackups", | |
"dynamodb:DescribeLimits", | |
"dynamodb:ListBackups", | |
"dynamodb:DescribeStream", | |
"dynamodb:DescribeTimeToLive", | |
"dynamodb:ListStreams", | |
"dynamodb:DescribeGlobalTableSettings", | |
"dynamodb:ListGlobalTables", | |
"dynamodb:DescribeGlobalTable", | |
"dynamodb:DescribeReservedCapacity", | |
"dynamodb:DescribeBackup", | |
], | |
resources: ['*'], | |
})) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment