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(aws-custom-resource): module fails loading when bundled with parcel #11487

Merged
merged 5 commits into from
Nov 19, 2020

Conversation

TheRealAmazonKendra
Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra commented Nov 16, 2020

After this change, aws-custom-resource will still not work properly when bundled using parcel, but at least the module won't throw an error anymore when it's being loaded.

Fixes #7284.

Since this change only impacted the way in which awsSdkMetadata was provided to awsSdkToIamAction no new tests were warranted, but I re-ran yarn build and all tests still passed.


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

@gitpod-io
Copy link

gitpod-io bot commented Nov 16, 2020

@@ -435,6 +429,7 @@ export class AwsCustomResource extends cdk.Construct implements iam.IGrantable {
*/
function awsSdkToIamAction(service: string, action: string): string {
const srv = service.toLowerCase();
const awsSdkMetadata = getAwsSdkMetadata();
Copy link
Contributor

Choose a reason for hiding this comment

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

We should cache this call, otherwise we are going to read and parse for every action in every AwsCustomResource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in revision.

@@ -435,6 +430,7 @@ export class AwsCustomResource extends cdk.Construct implements iam.IGrantable {
*/
function awsSdkToIamAction(service: string, action: string): string {
const srv = service.toLowerCase();
awsSdkMetadata = getAwsSdkMetadata();
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not like that the cache variable is written in one function and read in another. Responsibilities should be more clearly divided than that.

Please put the awsSdkMetadata global variable close to the getAwsSdkMetadata() function in the source, and make sure it's only referenced from that function. If you want to get fancy you can make it a closure, but just co-locating in the source, and maybe renaming to _awsSdkMetadataCache or something should inform people no other part of the code should be touching it.

After that, in places where it needs to be consumed (only here?), assing the result to a local variable and use that.

@rix0rrr rix0rrr changed the title fix(aws-custom-resource): aws-custom-resource fails when is missing fix(aws-custom-resource): module fails loading when bundled with parcel Nov 18, 2020
    This change makes getting the metadata a function instead of a const, fixes aws#7284.

    Since this change only impacted the way in which awsSdkMetadata was provided to awsSdkToIamAction no new tests were warranted, but I reran yarn build and all tests stull passed.
@mergify mergify bot dismissed rix0rrr’s stale review November 19, 2020 10:10

Pull request has been modified.

@rix0rrr rix0rrr added the pr-linter/exempt-test The PR linter will not require test changes label Nov 19, 2020
@mergify
Copy link
Contributor

mergify bot commented Nov 19, 2020

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: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 9402002
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify
Copy link
Contributor

mergify bot commented Nov 19, 2020

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).

@mergify mergify bot merged commit 421d4e4 into aws:master Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-linter/exempt-test The PR linter will not require test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-custom-resource fails when sdk-api-metadata.json is missing
4 participants