amazon-web-services - 当我尝试向网关添加新路由时,AWS 云形成总是失败
问题描述
我现在尝试了 7 次,但仍然失败。我正在向我的 API 网关添加一个新的路由端点。我已对云形成文件进行了必要的更改并将其上传到 AWS。
每次尝试,我得到以下错误,我不知道如何解决它。
'comp/*/*' is not a valid method path. Method paths can be defined as
{resource_path}/{http_method} for an individual method override,
or */* for overriding all methods in the stage.
(Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException;
Request ID: 0878sd34-4555-987s-3332-8dfg7d8f9;
Proxy: null)
这是云形成文件的一部分。
DevEnvStage:
Type: "AWS::ApiGateway::Stage"
Properties:
RestApiId: !Ref RestApi
StageName: 'dev'
Description: Stage for development environment
DeploymentId: !Ref FakeStageDeployment
CacheClusterEnabled: false
MethodSettings:
- HttpMethod: "*"
ResourcePath: "/red/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/yellow/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/blue/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/comp/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/dribl/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
Variables:
"": ""
QaEnvStage:
Type: "AWS::ApiGateway::Stage"
Properties:
RestApiId: !Ref RestApi
StageName: 'qa'
Description: Stage for development environment
DeploymentId: !Ref FakeStageDeployment
CacheClusterEnabled: false
MethodSettings:
- HttpMethod: "*"
ResourcePath: "/black/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/red/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/yellow/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/blue/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/comp/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
Variables:
"": ""
StageEnvStage:
Type: "AWS::ApiGateway::Stage"
Properties:
RestApiId: !Ref RestApi
StageName: 'stg'
Description: Stage for development environment
DeploymentId: !Ref FakeStageDeployment
CacheClusterEnabled: false
MethodSettings:
- HttpMethod: "*"
ResourcePath: "/black/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/red/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/yellow/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/blue/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/comp/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
Variables:
"": ""
ProdEnvStage:
Type: "AWS::ApiGateway::Stage"
Properties:
RestApiId: !Ref RestApi
StageName: 'prod'
Description: Stage for development environment
DeploymentId: !Ref FakeStageDeployment
CacheClusterEnabled: false
MethodSettings:
- HttpMethod: "*"
ResourcePath: "/yellow/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/red/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/red/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/blue/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/comp/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
- HttpMethod: "*"
ResourcePath: "/*"
CachingEnabled: true
CacheDataEncrypted: false
CacheTtlInSeconds: 180
Variables:
"Hostname": ""
DevEnvGatewayCustomDomain:
Type: "AWS::ApiGateway::DomainName"
Properties:
DomainName: ""
CertificateArn: ""
EndpointConfiguration:
Types:
- EDGE
DevEnvGatewayBasePathMapping:
Type: "AWS::ApiGateway::BasePathMapping"
Properties:
RestApiId: !Ref RestApi
DomainName: !Ref DevEnvGatewayCustomDomain
Stage: !Ref DevEnvStage
QaEnvGatewayCustomDomain:
Type: "AWS::ApiGateway::DomainName"
Properties:
DomainName: ""
CertificateArn: ""
EndpointConfiguration:
Types:
- EDGE
QaEnvGatewayBasePathMapping:
Type: "AWS::ApiGateway::BasePathMapping"
Properties:
RestApiId: !Ref RestApi
DomainName: !Ref QaEnvGatewayCustomDomain
Stage: !Ref QaEnvStage
StageEnvGatewayCustomDomain:
Type: "AWS::ApiGateway::DomainName"
Properties:
DomainName: ""
CertificateArn: ""
EndpointConfiguration:
Types:
- EDGE
StageEnvGatewayBasePathMapping:
Type: "AWS::ApiGateway::BasePathMapping"
Properties:
RestApiId: !Ref RestApi
DomainName: !Ref StageEnvGatewayCustomDomain
Stage: !Ref StageEnvStage
ProdEnvGatewayCustomDomain:
Type: "AWS::ApiGateway::DomainName"
Properties:
DomainName: ""
CertificateArn: ""
EndpointConfiguration:
Types:
- EDGE
ProdEnvGatewayBasePathMapping:
Type: "AWS::ApiGateway::BasePathMapping"
Properties:
RestApiId: !Ref RestApi
DomainName: !Ref ProdEnvGatewayCustomDomain
Stage: !Ref ProdEnvStage
正如您在方法设置部分中看到的那样。comp 的 HttpMehod 是“ /comp/*
”不是“ /comp/*/*
”
解决方案
您的 cloudformation 模板有问题
根据文档AWS::ApiGateway::Stage MethodSetting
- Http方法
HTTP 方法。要将设置应用于多个资源和方法,请在 HttpMethod 和 ResourcePath 中指定一个星号 (*)。
- 资源路径
此方法的资源路径。正斜杠 (/) 编码为 ~1,并且初始斜杠必须包含正斜杠。例如,路径值 /resource/subresource 必须编码为 /~1resource~1subresource。要指定根路径,请仅使用斜杠 (/)。要将设置应用于多个资源和方法,请在 HttpMethod 和 ResourcePath 中指定一个星号 (*)。
推荐阅读
- matplotlib - 具有不同标签/类别的区域之间的整齐轮廓
- angular - Angular 嵌套表单组件
- jmeter - Jmeter command line set heap size
- homebrew - 自制错误“kafka:没有可用的瓶子!” 我的 m1 macbook 上的第一个错误
- android - 未使用数据/主机意图过滤器调用 Android 接收器
- java - 如何将android studio stacktrace日志保存到设备内部存储中的文本文件中
- qt - 转换后如何访问我的自定义 QGraphicsItem 的数据属性的内容
- reactjs - OTT平台如何限制用户(如3流/账号)【设备限制】
- r - RStudio 不会在 Anaconda-Navigator 中启动
- snowflake-cloud-data-platform - 使用映射表中的多个字段的雪花行级策略