具有Cloudfront和Lambda @ Edge功能的无服务器框架

时间:2019-10-10 00:42:27

标签: amazon-cloudfront serverless-framework

我在下面使用此无服务器Yaml,并且尝试部署具有lambda @ edge浏览器请求和原始请求Labda的Cloudfront应用。

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

Could not find resource with logical name "CloudFrontDistribution"

这是非常通用的,Google搜索受到限制。

生成Cloudfront我缺少什么?

这是我的,谢谢!:

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

1 个答案:

答案 0 :(得分:0)

我使用的设置与您一样,效果很好。我认为错误在某种程度上是正确的。您粘贴的CloudFrontDistribution不完整。因此,它不是创建的。该错误传达给您的信息很少,因为它看起来是插件解决了问题,而不是核心应用。

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

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

相关问题