sst icon indicating copy to clipboard operation
sst copied to clipboard

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

Open mdnorman opened this issue 1 year ago • 2 comments

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 avatar Feb 11 '24 22:02 mdnorman

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.

mdnorman avatar Feb 11 '24 23:02 mdnorman

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.

jayair avatar Feb 15 '24 00:02 jayair