gpt4 book ai didi

amazon-web-services - AWS使用api网关部署Cloudfront

转载 作者:行者123 更新时间:2023-12-03 07:12:37 25 4
gpt4 key购买 nike

最近,我尝试使用 SAM 部署 lambda 函数和 Cloudfront 发行版以及 CloudFormation yaml 模板。但是,我在 CloudFormation 中遇到了 DomainName 问题,因为在实际部署 API 网关之前我没有 API 网关的 ID。

因此,我尝试使用 !Sub "${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"将 API Gateway 与 CF 发行版链接起来 作为 DomainName,但我收到以下错误:

资源处理程序返回消息:“提供的请求无效:参数源名称必须是域名。

我的代码如下:

AWSTemplateFormatVersion: 2010-09-09
Description: >-
cf-apigw-lambda-dynamodb

Transform:
- AWS::Serverless-2016-10-31

Resources:
getHeadersFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/get-items.getItemsHandler
Runtime: nodejs14.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 100
Description: Get all items
Events:
Api:
Type: Api
Properties:
Path: /items
Method: GET
CloudfrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: !Sub "${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
Id: ApiOrigin
CustomOriginConfig:
HTTPPort: 80
HTTPSPort: 443
OriginProtocolPolicy: https-only
Enabled: true
DefaultCacheBehavior:
TargetOriginId: ApiOrigin
ViewerProtocolPolicy: redirect-to-https
CachePolicyId: c17edf1f-cb61-49d6-979d-39f05ba95f91
OriginRequestPolicyId: c57eds1f-c8d1-4544-b8ce-6f4307e30d2e

Outputs:
WebEndpoint:
Description: "API Gateway endpoint URL for Prod stage"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"

最佳答案

DomainName 中不能有 /Prod/

DomainName: !Sub "${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com"

关于amazon-web-services - AWS使用api网关部署Cloudfront,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70930529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com