Skip to content

feat(s3-deployment): add deployedBucket attribute for sequencing #15384

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

Merged
merged 14 commits into from
Feb 18, 2022

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Jul 1, 2021

This allows referencing the bucket in a way that ensures the
deployment has happened before dependent resources are created.


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

This allows referencing the bucket in a way that ensures the
deployment has happened before dependent resources are created.

TODO:

- Tests
- Docstrings
- README
@gitpod-io
Copy link

gitpod-io bot commented Jul 1, 2021

@rix0rrr rix0rrr requested a review from skinny85 July 1, 2021 15:00
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 1, 2021
@BryanPan342
Copy link
Contributor

@rix0rrr would we consider this a breaking change? bc the asset id's change as a result of this! So some people who run tests might have their systems break.

@rix0rrr
Copy link
Contributor Author

rix0rrr commented Jul 2, 2021

@rix0rrr would we consider this a breaking change? bc the asset id's change as a result of this! So some people who run tests might have their systems break.

No. Snapshot testing w/ asset hashes is something people shouldn't be doing.

@rix0rrr
Copy link
Contributor Author

rix0rrr commented Jul 5, 2021

I can't approve this since I opened the PR. So we need @skinny85 in the game 🙂

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

LGTM. Two minor comments.

@@ -235,9 +250,12 @@ export class BucketDeployment extends CoreConstruct {
SystemMetadata: mapSystemMetadata(props),
DistributionId: props.distribution?.distributionId,
DistributionPaths: props.distributionPaths,
// Passing through the ARN sequences dependencees on the deployment
PassThroughBucketArn: props.destinationBucket.bucketArn,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we just use the existing DestinationBucketName to do this sequencing? Won't it have the same effect, without changing the customer's template?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I follow. If it doesn't change the template, it won't enforce sequencing, right?

Right now, the dependencies look like this, which lead to a race condition:

                                       ┌────────────────────┐
                     { Ref: Bucket }   │                    │
                          ┌────────────│     Deployment     │
                          │            │                    │
┌────────────┐            │            └────────────────────┘
│            │            │                                  
│   Bucket   │◀───────────┤                                  
│            │            │                                  
└────────────┘            │            ┌────────────────────┐
                          │            │                    │
                          └────────────│   BucketConsumer   │
                     { Ref: Bucket }   │                    │
                                       └────────────────────┘

We want them to look like this:

                                              { GetAtt: [..., 'BucketArn'] }               
┌────────────┐                 ┌────────────────────┐                ┌────────────────────┐
│            │ { Ref: Bucket } │                    │                │                    │
│   Bucket   │◀────────────────│     Deployment     │◀───────────────│   BucketConsumer   │
│            │                 │                    │                │                    │
└────────────┘                 └────────────────────┘                └────────────────────┘

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant template changes related to the new PassThroughBucketArn property that you added, regardless of whether your customers use the new deployedBucket property or not.

If you used the existing DestinationBucketName property for this purpose, I believe existing customers would not have their template affected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see. Is that good enough though? What if the bucket is in another account?

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's in another account, sequencing within the template with Fn::GetAtt is irrelevant anyway 🙂.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is true, using the bucket still shouldn't fail.

},
});

this.deployedBucket = s3.Bucket.fromBucketArn(this, 'DestinationBucket', Token.asString(deployment.getAtt('DestinationBucketArn')));
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty sure we're missing a unit test for actually using this property in another construct.

@skinny85 skinny85 added the pr/do-not-merge This PR should not be merged at this time. label Jul 6, 2021
@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Aug 13, 2021
@mergify
Copy link
Contributor

mergify bot commented Feb 18, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 1ad1719
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit edac101 into master Feb 18, 2022
@mergify mergify bot deleted the huijbers/deployed-bucket branch February 18, 2022 12:04
@mergify
Copy link
Contributor

mergify bot commented Feb 18, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
…ws#15384)

This allows referencing the bucket in a way that ensures the
deployment has happened before dependent resources are created.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3-deployment contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants