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

feat(cloudfront): find and replace text in the code of CloudFront Functions during synth #30621

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

SydneyUni-Jim
Copy link
Contributor

@SydneyUni-Jim SydneyUni-Jim commented Jun 22, 2024

Issue # (if applicable)

Closes #30492

Reason for this change

Primarily to allow deploying a CloudFront Function and its Key/Value Store in the same stack, without having to deploy the Key/Value Store first, manually retrieve its ID, and then hardcode the ID into the Function's code.

Secondarily to allow other values in a CloudFront Function's code to be changed when deploying into different environments, dev verses prod for example.

Description of changes

  • aws_cloudfront/README.md
    • Update the CloudFront Functions and Key Value Store sections.
  • aws_cloudfront/function.ts
    • Add struct FunctionCodeFindReplace.
    • Add struct FunctionCodeOptions, with the optional findReplace property.
    • Change struct FileCodeOptions to extend FunctionCodeOptions.
    • Add struct InlineCodeOptions, which extends FunctionCodeOptions with no additional properties.
      • For symmetry with FileCodeOptions and as a future extension point.
    • Add an optional options parameter to FunctionCode.fromInline.
    • Add private method FunctionCode.findReplace.
    • Change InlineCode.render to call FunctionCode.findReplace.
    • Change FileCode.render to call FunctionCode.findReplace.

Backwards compatible API changes

  • FunctionCode.fromInline gains a second optional parameter.
  • FileCodeOptions gains an optional findReplace property.

Description of how you validated changes

  • Add describe('find/replace in function code'… to function.test.ts.
  • Add integ.function-find-replace.ts
    • Deploys a CloudFront distribution, function, and key-value store.
    • Use find/replace to get the ID of the key-value store into the function.
    • Exercises the function to test the function can access the key-value store.

Checklist


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

@aws-cdk-automation aws-cdk-automation requested a review from a team June 22, 2024 07:54
@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Jun 22, 2024
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.

@SydneyUni-Jim SydneyUni-Jim changed the title Issue 30492 feat(aws-cloudfront): Parameterise CloudFront Functions via find/replace Jun 22, 2024
@SydneyUni-Jim SydneyUni-Jim changed the title feat(aws-cloudfront): Parameterise CloudFront Functions via find/replace feat(cloudfront): Parameterise CloudFront Functions via find/replace Jun 22, 2024
@SydneyUni-Jim SydneyUni-Jim changed the title feat(cloudfront): Parameterise CloudFront Functions via find/replace feat(cloudfront): parameterise CloudFront Functions via find/replace Jun 22, 2024
@SydneyUni-Jim SydneyUni-Jim changed the title feat(cloudfront): parameterise CloudFront Functions via find/replace feat(cloudfront): find and replace the code of CloudFront Functions Jun 22, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review June 22, 2024 13:45

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

@SydneyUni-Jim SydneyUni-Jim marked this pull request as ready for review June 22, 2024 13:51
@SydneyUni-Jim SydneyUni-Jim marked this pull request as draft June 22, 2024 14:26
@SydneyUni-Jim SydneyUni-Jim marked this pull request as ready for review June 23, 2024 08:19
@SydneyUni-Jim
Copy link
Contributor Author

SydneyUni-Jim commented Jun 23, 2024

In the last PR Linter / validate-pr, node core dumped from a bus error. The prior validate-pr had succeeded.

[4/4] Building fresh packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
error /home/runner/work/aws-cdk/aws-cdk/node_modules/@lerna/create/node_modules/nx, /home/runner/work/aws-cdk/aws-cdk/node_modules/@nx/devkit/node_modules/nx, /home/runner/work/aws-cdk/aws-cdk/node_modules/lerna/node_modules/nx: Command failed.
Exit code: 135
Command: node ./bin/post-install
Arguments: 
Directory: /home/runner/work/aws-cdk/aws-cdk/node_modules/@nx/devkit/node_modules/nx
Output:
Bus error (core dumped)
Error: Process completed with exit code 135.

@SydneyUni-Jim SydneyUni-Jim changed the title feat(cloudfront): find and replace the code of CloudFront Functions feat(cloudfront): find and replace text in the code of CloudFront Functions during synth Jun 23, 2024
@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 Jun 23, 2024
This was referenced Jun 24, 2024
@SydneyUni-Jim SydneyUni-Jim force-pushed the issue-30492 branch 2 times, most recently from 64606b6 to e19ed62 Compare July 18, 2024 06:05
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(cloudfront): parameterise CloudFront Functions via find/replace
2 participants