Skip to content
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

fix(dynamodb): replication regions are incompatible with resource policies in TableV2 #31097

Closed
wants to merge 9 commits into from

Conversation

LeeroyHannigan
Copy link
Contributor

Issue # (if applicable)

Closes #30705

Reason for this change

Resource policies were shared across all replicas in a region.

Description of changes

Changed the logic to only apply resource policy to the local replica region, or to specific replicas only when defined.

Description of how you validated changes

Unit tests were conducted

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Aug 13, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team August 13, 2024 17:07
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@LeeroyHannigan LeeroyHannigan changed the title fix(dynamodb) - Replication regions are incompatible with resource policies in TableV2 fix(dynamodb): replication regions are incompatible with resource policies in TableV2 Aug 13, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review August 13, 2024 19:06

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Aug 13, 2024
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why this changes are needed to help me understand? What's the current behaviour and issue when setting the resoruce policies in the replication regions?

@LeeroyHannigan
Copy link
Contributor Author

The issue is defined in #31097

Do you require more information than is supplied there?

packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts Outdated Show resolved Hide resolved

//const resourcePolicy = props.resourcePolicy ?? this.tableOptions.resourcePolicy;
//const resourcePolicy = props.resourcePolicy;
const resourcePolicy = (props.region === this.region ? this.tableOptions.resourcePolicy : props.resourcePolicy) || undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change for existing users. If existing users manage to bypass the CFN error by using escape hatch. They then remove the escape hatch and upgrade to a version that includes this change, their replication region will now have the resource policies removed, thus this is not an acceptable change. I would recommend you to do it following the suggested proposal in the original issue.

Ideally, the construct could allow null and when null is specified in a specific replica, no resourcePolicy is added to that replica even when one is defined in the TableV2 itself

new TableV2(this, `MyTable-${stage}`, {
      pointInTimeRecovery: true,
      partitionKey: {
        name: 'key',
        type: AttributeType.STRING,
      },
      tableName: 'MyTable',
      // us-east-2 should not have tablePolicyDocument added in the template
      replicas: [{ region: 'us-east-1' }, { region: 'us-east-2', resourcePolicy: null }], 
      resourcePolicy: tablePolicyDocument,
    });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is forcing a user to add null for when they don't want a resource policy. The default implementation should only require them to add a policy to a replica should the want it. It shouldn't default to adding it to all replicas.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Aug 20, 2024
@mergify mergify bot dismissed GavinZZ’s stale review August 21, 2024 17:53

Pull request has been modified.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Aug 21, 2024
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 973a379
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM, some minor feedbacks on the integ tests.

Comment on lines +28 to +35
new dynamodb.TableV2(this, 'TableTestV2', {
partitionKey: {
name: 'id',
type: dynamodb.AttributeType.STRING,
},
removalPolicy: RemovalPolicy.DESTROY,
resourcePolicy: docu,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't seem to test for replica?

Comment on lines +52 to +55
],
"StreamSpecification": {
"StreamViewType": "NEW_AND_OLD_IMAGES"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this change from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stream came from adding a replica.

    table.addReplica({
      region: 'eu-west-2',
    });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's good to know.

Comment on lines +34 to +36
table.addReplica({
region: 'eu-west-2',
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test didn't even set the feature flag, so my understanding is that it should use the table's resource policy but doesn't seem to be the case in the output template.json. May I ask how you ran the tests locally and update the snapshot?

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Aug 28, 2024
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

1 similar comment
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@LeeroyHannigan
Copy link
Contributor Author

Had some issues with building so pushed a fresh version #31513

Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dynamodb: Replication regions are incompatible with resource policies in TableV2
3 participants