-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(cloudfront): parameterise CloudFront Functions via find/replace #30492
Comments
It would be great if |
Possible implementation of protected findReplace(code: string, findReplaceArr?: FindReplace[]): string {
if (!findReplaceArr?.length) return code
function reducer(acc: string, opt: FindReplace) {
const r: string = typeof opt.replace === 'string' ? opt.replace : cdk.Token.asString(opt.replace)
return opt.all ? acc.replaceAll(opt.find, r) : acc.replace(opt.find, r)
}
return findReplaceArr.reduce(reducer, code)
} |
Hi @SydneyUni-Jim , thanks for reaching out. I see this readme doc talks about Key-value store ,quite similar to what you have proposed in solution. I might not fully comprehend about the solution but we are open to suggestions and please feel free to submit a PR ! |
HI @khushail. Thanks for pointing out the docs. Unfortunately that only associates the Key Value Store with the function. It doesn't make the store's id available to the function's code. I will work on a PR. |
Describe the feature
CloudFront Functions (not Lambda@Edge) don't provide a way to parameterise the code, in the way environment variables can with Lambda@Edge, for example. Allow code to be replaced with values from the CDK app during synth.
Use Case
Proposed Solution
In aws-cdk-lib/aws-cloudfront/lib/function.ts:
This is a naïve find (all) and replace. It does not attempt to parse the function code to find appropriate tokens. It does not attempt to replace code meaningfully. There is no guarantee that syntactically valid code remains syntactically valid after the find/replace.
Proof of concept
This is the code I'm currently using to get the KVS ID into a CloudFront Function. The proposed solution is a generalisation of this.
Example of using the proposed solution
Given this code for a CloudFront Function.
__KVS_ID__ and __IS_PROD__ could be replaced in the code with this.
If the KVS id is
61736184-1ad9-4b1b-9466-6ca1fb629685
and isProd isfalse
, the code that would be sent to CloudFront would be this.Other Information
The Key Value Store can be used for parameterisation. But there's costs associated with that. And there's the conundrum of how to get the KVS ID into the CloudFront Function to begin with.
Acknowledgements
CDK version used
2.145.0
Environment details (OS name and version, etc.)
NodeJS/iron
The text was updated successfully, but these errors were encountered: