Devin
02/17/2022, 7:59 PMsrc/
. my project is in us-east-1
. Below is a simplified version of my code.
import * as sst from "@serverless-stack/resources";
import { LambdaEdgeEventType, experimental } from "aws-cdk-lib/aws-cloudfront";
import * as lambda from "aws-cdk-lib/aws-lambda";
export default class MarketingStack extends sst.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const originRewriteHandler = new experimental.EdgeFunction(
this,
"OriginRewriteFunc",
{
runtime: lambda.Runtime.NODEJS_14_X,
handler: "src/rewriter.main",
}
);
const staticSite = new sst.StaticSite(this, "Site", {
path: "website",
errorPage: "404.html",
buildOutput: "public",
buildCommand: "npm run build",
});
staticSite.cfDistribution.addBehavior("/*", staticSite.s3Bucket, {
edgeLambdas: [
{
functionVersion: originRewriteHandler.currentVersion,
eventType: LambdaEdgeEventType.ORIGIN_REQUEST,
},
],
});
}
}
When I try to tun this I get a type error that it can’t read bind of undefined
. Which makes sense since I have no idea what I’m doing 🤣 . Actually, I figure that it’s trying to connect the bucket and the lambda but I’m missing something. I don’t really kno how to debug this.Frank
Devin
02/21/2022, 9:03 PMTypeError: Cannot read property 'bind' of undefined
at new Function (/Users/devinfitzsimons/Backup/serverless-stack/comics-helper/node_modules/aws-cdk-lib/aws-lambda/lib/function.ts:350:29)
at EdgeFunction.createInRegionFunction (/Users/devinfitzsimons/Backup/serverless-stack/comics-helper/node_modules/aws-cdk-lib/aws-cloudfront/lib/experimental/edge-function.ts:122:26)
at new EdgeFunction (/Users/devinfitzsimons/Backup/serverless-stack/comics-helper/node_modules/aws-cdk-lib/aws-cloudfront/lib/experimental/edge-function.ts:44:14)
at new MarketingStack (/Users/devinfitzsimons/Backup/serverless-stack/comics-helper/stacks/MarketingSiteStack.js:27:34)
at Object.main (/Users/devinfitzsimons/Backup/serverless-stack/comics-helper/stacks/index.js:12:3)
at Object.<anonymous> (/Users/devinfitzsimons/Backup/serverless-stack/comics-helper/.build/run.js:94:16)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
Devin
02/21/2022, 9:08 PMcode From AssetPath
portionFrank
code
to EdgeFunction
Devin
02/22/2022, 12:23 AMDevin
02/22/2022, 12:26 AMFrank
const myFunc = new cloudfront.experimental.EdgeFunction(this, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_12_X,
handler: 'index.handler',
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
});
You want to point the code path to the directory where the Lambda handler is. In this case, it’s pointing to the “lambda-handler” directory relative to where the stack file is.