Tim V
03/01/2022, 5:21 PMThe Lambda function associated with the CloudFront distribution is invalid or doesn't have the required permissions.
Here's my setup...
const viewerRequest = new Function(this, "viewer-request", {
handler: "stack/cloudfront/viewer-request.handler",
memorySize: 128,
timeout: 5,
// permissions: [
// new PolicyStatement({
// effect: Effect.ALLOW,
// actions: ["lambda:InvokeFunction"],
// resources: [viewerRequestHandler.functionArn],
// }),
// ],
});
viewerRequest.node.host.environment = {};
viewerRequest.node.host.role.assumeRolePolicy.statements = [
new PolicyStatement({
effect: Effect.ALLOW,
actions: ["sts:AssumeRole"],
principals: [
new ServicePrincipal("<http://lambda.amazonaws.com|lambda.amazonaws.com>"),
new ServicePrincipal("<http://edgelambda.amazonaws.com|edgelambda.amazonaws.com>"),
],
})
];
const site = new StaticSite(this, "website", {
path: "stack/website",
buildOutput: "dist",
buildCommand: "yarn build",
environment: { API_ENDPOINT: api.url },
disablePlaceholder: true,
cfDistribution: {
priceClass: PriceClass.PRICE_CLASS_100,
defaultBehavior: {
allowedMethods: ["GET"],
edgeLambdas: [{
eventType: LambdaEdgeEventType.VIEWER_REQUEST,
functionVersion: viewerRequest.currentVersion,
}],
},
// additionalBehaviors: {
// "/files": {
// origin: new S3Origin(bucket.s3Bucket),
// allowedMethods: ["GET"],
// edgeLambdas: [{
// eventType: LambdaEdgeEventType.VIEWER_REQUEST,
// functionVersion: viewerRequest.currentVersion,
// }],
// },
// },
},
});
Tim V
03/01/2022, 5:22 PMTim V
03/01/2022, 6:42 PMexport const handler = async event => {
console.log(JSON.stringify(event, null, 2));
return event;
};
Frank
sst.Function
currently doesn’t support Edge functions.Frank
cloudfront.experimental.EdgeFunction
construct to create an Edge function.Frank
Frank
Tim V
03/02/2022, 4:40 AM