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

Using a Lambda@Edge function requires 'cdk bootstrap' to be run #3666

Open
mdnorman opened this issue Feb 11, 2024 · 2 comments
Open

Using a Lambda@Edge function requires 'cdk bootstrap' to be run #3666

mdnorman opened this issue Feb 11, 2024 · 2 comments

Comments

@mdnorman
Copy link

I'm trying to use a Lambda@Edge function in a StaticSite (based on the docs), but whenever I add the function while running locally, I get a stack error:

stack: mnorman-myproject-distEdgeFunction: SSM parameter /cdk-bootstrap/abcdefgh/version not found. Has the environment been bootstrapped? Please run 'cdk bootstrap' (see https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html)

Relevant stack setup:

  const edgeFunction = new experimental.EdgeFunction(
    stack,
    "distEdgeFunction",
    {
      runtime: Runtime.NODEJS_18_X,
      code: Code.fromAsset("packages/functions/src/project"),
      handler: "edge.handler",
      stackId: `${app.logicalPrefixedName("distEdgeFunction")}`,
    },
  );

  const dist = new StaticSite(stack, "dist", {
    cdk: {
      distribution: {
        defaultBehavior: {
          origin: new S3Origin(bucket.cdk.bucket, {}),
          viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
          trustedKeyGroups: [keyGroup],
          edgeLambdas: {
            functionVersion: edgeFunction.currentVersion,
            eventType: LambdaEdgeEventType.VIEWER_REQUEST,
          },
        },
        enableLogging: true,
      },
    },
  });

If I take out the edge lambda, there are no problems with local development, so it has something to do with local development and creating an edge function.

I wanted to use the EdgeFunction contract, but that doesn't appear to be exposed in the sst/constructs API.


If you've already posted your issue on Discord, make sure to leave a link to it here.

@mdnorman
Copy link
Author

No sooner than I had written this, it appears that running cdk bootstrap aws://<accountid>/us-east-1 will solve the problem.

Maybe there's a way to configure SST to do this when not using us-east-1 for other resources, but I couldn't find any options in cdk-bootstrap config.

@jayair
Copy link
Contributor

jayair commented Feb 15, 2024

Ah interesting. Yeah these CDK resources need to specifically go to us-east-1. Running the CDK command works. We should also document that you can run sst bootstrap and that'll do the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants