具有 Cloudfront 和 Lambda@Edge 函数的无服务器框架



我在下面使用这个无服务器 yaml,我正在尝试部署一个具有lambda@edge查看器请求和源请求 labdas 的 cloudfront 应用程序。

如果我排除任何 cloudfront yaml 指令,我可以部署两个 lambda。但是当我添加 cloudfront 指令时,sls deploy错误

Could not find resource with logical name "CloudFrontDistribution"

这是非常通用的,谷歌搜索是有限的。

生成 Cloudfront 时缺少什么?

这是我的yml,提前感谢!

service: ${file(serverless-config/vars-config.yml):service}
custom:
objectPrefix: '${self:service}-${self:provider.stage}'
scripts:
hooks:
package:initialize: make compile
plugins:
- '@silvermine/serverless-plugin-cloudfront-lambda-edge'
- serverless-plugin-scripts
provider:
name: aws
runtime: go1.x
stage: production
profile: production
timeout: 300
region: ${file(serverless-config/vars-config.yml):region}
functions:
viewerRequestPostGetRewriteHandler:
name: '${self:custom.objectPrefix}-viewer-request'
handler: app/functions/ViewerRequestPostGetRewriteHandler.main
memorySize: 128
timeout: 1
events:
lambdaAtEdge:
distribution: CloudFrontDistribution
eventType: viewer-request
originRequestGetPostRewriteHandler:
name: '${self:custom.objectPrefix}-viewer-request'
handler: app/functions/OriginRequestGetPostRewriteHandler.main
memorySize: 128
timeout: 1
events:
lambdaAtEdge:
distribution: CloudFrontDistribution
eventType: origin-request
resources:
Resources:
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
PriceClass: PriceClass_100

我使用像你一样的设置,效果很好。我认为这个错误在某种程度上是正确的。粘贴的CloudFrontDistribution不完整。因此,它没有被创建。该错误与您沟通不畅,因为看起来插件发现了问题,而不是核心应用程序。

为了证明我的理论,请继续尝试在不激活插件的情况下启动,您应该会看到与无效AWS::CloudFront::Distribution资源相关的更好错误。

要解决此问题:配置有效的 CloudFormation 资源。使用此处的示例来获得灵感: https://github.com/silvermine/serverless-plugin-cloudfront-lambda-edge#example-cloudfront-static-site-serverless-config

最新更新