Hey guys, I want to use Lambda@Edge to read my use...
# sst
a
Hey guys, I want to use Lambda@Edge to read my user’s country, I’m trying to deploy a function as described here, but can’t get it to work: https://docs.serverless-stack.com/constructs/StaticSite#using-lambdaedge
Copy code
Error: ENOENT: no such file or directory, copyfile '/Users/amouly/Projects/project/project-serverless/node_modules/@aws-cdk/core/lib/custom-resource-provider/nodejs-entrypoint.js' -> '/Users/amouly/Projects/project/project-serverless/.build/lib/edge-function/__entrypoint__.js'
@Frank do you know if there is an example of using lamnda@edge?
f
Hey @Adrián Mouly, can you paste a couple of more lines before and after the ENOENT error?
a
I’ve ended up deleting this function.
😞
I want to read the user country and return it.
But can’t get it to work.
f
hmm.. which region is ur StaticSite deployed to?
a
To AP-1-east.
f
ic.. and you are getting the error at build time right?
a
I was reading that only US-EAST1 is suported.
Yes.
Build time.
I was reading CDK and they said is going to boostrap on other location.
But I didn’t get to that step.
Looks like the problem is reading function code.
f
yeah, edge functions have to be deployed to us-east-1. If you are using the cloudfront.experimental.EdgeFunction construct, that’s done for u behind the scene.
a
Yes, exactly.
f
Can I see how were u creating the edge function and assigning it to the Distribution?
a
Yes, one sec.
Well I did exactly what is on the example.
I don’t have much more.
Maybe my problem is hot I referemce the folder.
Copy code
const edgeFunc = new experimental.EdgeFunction(this, "MyFunction", {
  runtime: lambda.Runtime.NODEJS_12_X,
  handler: "lambda.handler",
  code: lambda.Code.fromAsset("path/to/dir"),
  stackId: `${scope.logicalPrefixedName("edge-lambda")}`,
})
That’s why I was wondering if there is a working example.
But anyway, I’m not going to use this, my use case is.. “detect user country”… but it doesn’t look like I can do that from StaticSite.
I wanted to detect country and modify the
index.html
content with this value (adding a <tag>).
f
I see. I’m in the middle of something. Let me put together an example after.
a
Sure.
Thank you.