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): associate key value stores to functions #28571

Merged
merged 9 commits into from
Jan 24, 2024

Conversation

laurelmay
Copy link
Contributor

@laurelmay laurelmay commented Jan 4, 2024

CloudFormation now supports specifying KeyValueStoreAssocations on a AWS::CloudFront::Function. This adds that support to the CDK. Even though the field is plural (in CloudFormation and the API), a function can have one value store so the implementation here tries to provide a nicer API around that.

If a Key Value Store is specified, the function will default to js-2.0 instead of js-1.0. Behavior for existing functions is retained. Additionally, an error is thrown if 1.0 is used.

Closes #28377.


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 effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 star-contributor [Pilot] contributed between 25-49 PRs to the CDK labels Jan 4, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team January 4, 2024 01:54
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.

@aws-cdk-automation aws-cdk-automation dismissed their stale review January 4, 2024 02:03

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

@laurelmay
Copy link
Contributor Author

@Mergifyio update

Copy link
Contributor

mergify bot commented Jan 8, 2024

update

✅ Branch has been successfully updated

@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 Jan 10, 2024
Copy link
Contributor

@go-to-k go-to-k left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! I made a few comments.

packages/aws-cdk-lib/aws-cloudfront/lib/function.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-cloudfront/lib/function.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-cloudfront/test/function.test.ts Outdated Show resolved Hide resolved
Comment on lines +259 to +275

test('no value is used in CloudFormation when unspecified in CDK', () => {
const stack = new Stack();

new Function(stack, 'TestFn', {
code: FunctionCode.fromInline('code'),
runtime: FunctionRuntime.JS_2_0,
keyValueStore: undefined,
});

Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', {
FunctionConfig: {
KeyValueStoreAssociations: Match.absent(),
},
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see much need for this, but what do you think? (unless you intend to make sure that it is not generated with an empty array, or something like that.)

Suggested change
test('no value is used in CloudFormation when unspecified in CDK', () => {
const stack = new Stack();
new Function(stack, 'TestFn', {
code: FunctionCode.fromInline('code'),
runtime: FunctionRuntime.JS_2_0,
keyValueStore: undefined,
});
Template.fromStack(stack).hasResourceProperties('AWS::CloudFront::Function', {
FunctionConfig: {
KeyValueStoreAssociations: Match.absent(),
},
});
});
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think I like it being explicit that it should be left absent instead of perhaps an empty list. I agree it's perhaps covered by other cases or less critical but it does feel like an important way to preserve the correct behavior at a CloudFormation layer.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I agree. Let's go ahead with this.

@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 Jan 21, 2024
Co-authored-by: k.goto <24818752+go-to-k@users.noreply.github.com>
Copy link
Contributor

@go-to-k go-to-k left a comment

Choose a reason for hiding this comment

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

Looks good.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 22, 2024
Copy link
Contributor

@gracelu0 gracelu0 left a comment

Choose a reason for hiding this comment

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

Thank you for contributing! Left a tiny comment but otherwise LGTM :)

Copy link
Contributor

mergify bot commented Jan 24, 2024

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

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 24, 2024
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 84bcc2f
  • 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 5ede456 into aws:main Jan 24, 2024
12 checks passed
Copy link
Contributor

mergify bot commented Jan 24, 2024

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

Vandita2020 pushed a commit to Vandita2020/aws-cdk that referenced this pull request Jan 30, 2024
CloudFormation now supports specifying [`KeyValueStoreAssocations`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-function-keyvaluestoreassociation.html) on a `AWS::CloudFront::Function`. This adds that support to the CDK. Even though the field is plural (in CloudFormation and the API), [a function can have one value store](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/kvs-with-functions-associate.html) so the implementation here tries to provide a nicer API around that.

If a Key Value Store is specified, the function will default to `js-2.0` instead of `js-1.0`. Behavior for existing functions is retained. Additionally, an error is thrown if 1.0 is used.

Closes aws#28377.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
SankyRed pushed a commit that referenced this pull request Feb 8, 2024
CloudFormation now supports specifying [`KeyValueStoreAssocations`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-function-keyvaluestoreassociation.html) on a `AWS::CloudFront::Function`. This adds that support to the CDK. Even though the field is plural (in CloudFormation and the API), [a function can have one value store](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/kvs-with-functions-associate.html) so the implementation here tries to provide a nicer API around that.

If a Key Value Store is specified, the function will default to `js-2.0` instead of `js-1.0`. Behavior for existing functions is retained. Additionally, an error is thrown if 1.0 is used.

Closes #28377.

----

*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
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-cloudfront: support KeyValueStore
5 participants