-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to rename DynamoDB tables in Gen 2? #2991
Comments
Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂 |
It is not possible to change the DynamoDB table names currently. The DynamoDB tables are stored in
backend.data.resources.cfnResources.amplifyDynamoDbTables.Todo
// @ts-expect-error
.resource // private property
.addPropertyOverride("tableName", "MyCustomTableName"); I don't know why
|
@dpilch Thanks for the quick response, I appreciate it. I guess I am making a feature request, to allow us to provide clean, user friendly names to not mess up the UI in the AWS Console and give a predictable outcome for the table names. For example I have a project with 1 sandbox env, dev and prod with 7 models. The tables in the account look really messy and hard to understand/easy to make a mistake when selecting tables to perform actions on/inspect configuration etc Other than that keep up the great work! |
Any update on a solution for providing a name for Amplify generated tables? It'd be much better to allow user-defined, meaningful table names instead of relying on a random UUID table name. I see that this PR was closed... is there another solution available? |
We discovered some issues in the implementation and are assessing some alternatives. I have a workaround, but it does have some issues. The The workaround uses the private property and adds the necessary policy changes. Using the workaround would be at your own risk due to the private property. import { Role, PolicyStatement, Effect } from 'aws-cdk-lib/aws-iam';
export const backend = defineBackend({
auth,
data,
});
backend.data.resources.cfnResources.amplifyDynamoDbTables.Todo
// @ts-expect-error
.resource // private property
.addPropertyOverride("tableName", "MyCustomTableName");
// update Amplify DDB table manager policy to add custom table name
const policy = new PolicyStatement({
effect: Effect.ALLOW,
actions: [
'dynamodb:CreateTable',
'dynamodb:UpdateTable',
'dynamodb:DeleteTable',
'dynamodb:DescribeTable',
'dynamodb:DescribeContinuousBackups',
'dynamodb:DescribeTimeToLive',
'dynamodb:UpdateContinuousBackups',
'dynamodb:UpdateTimeToLive',
'dynamodb:TagResource',
'dynamodb:UntagResource',
'dynamodb:ListTagsOfResource',
],
resources: [
Fn.sub('arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}', {
tableName,
}),
],
});
const onEventRole = backend
.data
.resources
.nestedStacks
.AmplifyTableManager
.node
.findChild('AmplifyManagedTableOnEventRole') as Role;
const isCompleteRole = backend
.data
.resources
.nestedStacks
.AmplifyTableManager
.node
.findChild('AmplifyManagedTableIsCompleteRole') as Role;
onEventRole.addToPolicy(policy);
isCompleteRole.addToPolicy(policy);
backend.data.resources.cfnResources.cfnRoles.TodoIAMRole.addPropertyOverride(
"Policies.0.PolicyDocument.Statement.0.Resource",
[
"arn:aws:dynamodb:us-west-2:<aws-account-id>:table/MyCustomTableName",
"arn:aws:dynamodb:us-west-2:<aws-account-id>:table/MyCustomTableName/*",
]
); |
Amplify CLI Version
Gen 2
Question
I really like Amplify but I find the resource name excruciatingly annoying, specially when deploying multiple branches/sandboxes in one AWS Account.
I am trying to rename core resources, such as userpool, lambda function etc, and I want to do the same with DynamoDB table but I don't seem to be able to get the Cloudformation reference because its in a nested stack, is it possible?
The text was updated successfully, but these errors were encountered: