Yes I did use a CloudFront Distribution and the serverless-plugin-cloudfront-lambda-edge.
The problem is the authorization headers part though. You need to sign the request with aws4 but CloudFront won’t allow you to replace the Host header and so the aws4 signature will not match and return
{“message”:“The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.”}
I also tried generasting the aws4 signature with the cloudfront Host header but then I would get:
AccessDeniedException>
Unable to determine service/operation name to be authorized
// serverless.yml
{
"service": "service",
"provider": {
"name": "aws",
"runtime": "nodejs8.10",
"stage": "${opt:stage, 'development'}",
"region": "us-east-1",
"memorySize": "512",
"timeout": "10"
},
"functions": {
"index": {
"handler": "handler.index",
"memorySize": 256
},
"requestRewriter": {
"handler": "requestRewriter.handler",
"memorySize": 128,
"timeout": 1,
"lambdaAtEdge": {
"distribution": "CloudfrontDistributionProduction",
"eventType": "viewer-request"
}
}
},
"resources": {
"Resources": {
"CloudfrontDistributionProduction": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"DistributionConfig": {
"Origins": [{
"DomainName": "lambda.us-east-1.amazonaws.com",
"Id": "api",
"CustomOriginConfig": {
"HTTPPort": "80",
"HTTPSPort": "443",
"OriginProtocolPolicy": "match-viewer"
}
}],
"Enabled": "true",
"Aliases": ["*.mydomain.com"],
"DefaultCacheBehavior": {
"AllowedMethods": ["HEAD", "DELETE", "POST", "GET", "OPTIONS", "PUT", "PATCH"],
"DefaultTTL": 0,
"MaxTTL": 0,
"MinTTL": 0,
"TargetOriginId": "api",
"ForwardedValues": {
"QueryString": false,
"Headers": ["*"],
},
"ViewerProtocolPolicy": "allow-all",
"Compress": true
},
"ViewerCertificate": {
"AcmCertificateArn": "arn:aws:acm:us-east-xxx",
"SslSupportMethod": "sni-only"
}
}
}
}
}
},
"plugins": [
"serverless-plugin-cloudfront-lambda-edge"
],
"custom": {
"webpackIncludeModules": {
"forceExclude": ["aws-sdk"]
}
}
}