【问题标题】:Serverless Framework with Cloudfront and Lambda@Edge functions具有 Cloudfront 和 Lambda@Edge 功能的无服务器框架
【发布时间】:2023-03-13 02:05:02
【问题描述】:

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

如果我排除任何云端 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

【问题讨论】:

    标签: amazon-cloudfront serverless-framework


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2017-09-30
      • 2020-03-20
      • 1970-01-01
      • 2019-09-06
      • 1970-01-01
      • 2018-02-19
      • 2020-09-25
      • 2020-10-17
      • 2021-04-01
      相关资源
      最近更新 更多