-
-
Notifications
You must be signed in to change notification settings - Fork 457
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
CDK: switch to CloudFront EdgeFunction #951
Comments
Hey Arjun, this sounds great. I'm hesitant to jump in a use an experimental module, although either way, I'll have a play with this myself. |
Hi, I just tried the switch to EdgeFunction by myself and it works in my scenario (just using the regeneration and default lambda). Cheers |
The role it assigns is the default one given... I just commented out the manual role assignment and it works. diff --git a/node_modules/@sls-next/cdk-construct/dist/index.js b/node_modules/@sls-next/cdk-construct/dist/index.js
|
Thanks for the workaround @w0otness 👌 For the maintainers, would you accept a PR that would propose this change as an option in the construct props? Meanwhile, here is a snippet of the patch if anyone is interested: import * as fs from 'fs';
import * as path from 'path';
import * as cdk from 'aws-cdk-lib';
async function patchConstructCode() {
const filePath = path.join(__dirname, 'node_modules/@sls-next/cdk-construct/dist/index.js');
const fileContent = await (await fs.promises.readFile(filePath)).toString();
await fs.promises.writeFile(
filePath,
fileContent.replace('lambda.Function(this, "NextLambda"', 'aws_cloudfront_1.experimental.EdgeFunction(this, "NextLambda"')
.replace('role: this.edgeLambdaRole', '// role: this.edgeLambdaRole'),
);
}
patchConstructCode()
.then(() => import('@sls-next/lambda-at-edge'))
.then(({ Builder }) => {
const builder = new Builder('.', './build', { args: ['build'] });
builder.build();
})
.then(() => {
const app = new cdk.App();
new MyStack(app, 'MyStack');
})
.catch((e) => {
console.log(e);
process.exit(1);
}); |
Any updates on this? |
Is your feature request related to a problem? Please describe.
At the moment, CDK stacks have to be deployed to us-east-1 because of the Lambda@Edge function.
Describe the solution you'd like
The CloudFront module provides a (experimental)
EdgeFunction
module that behaves exactly like a normalFunction
, however if the stack is deployed to a region that isn't us-east-1, it will isolate the function into a new stack and create the function in the correct region.Current blockers
I've tried to switch to
EdgeFunction
locally, and there are a few issues:version aliases clash (issue)fixedRe the circular dependency, the only solution seems to be using another stack and importing the role in. We could have 'support' constructs that go into a separate shared stack, which would also solve #947.
The text was updated successfully, but these errors were encountered: