我正在尝试将 OpenApi 规范包含到我的 AWS::Serverless::Api
DefinitionBody
中,如下所示:
MyApi:
Type: "AWS::Serverless::Api"
Properties:
StageName: 'dev'
Domain:
DomainName: 'mydomain.com'
CertificateArn: 'my-arn'
EndpointConfiguration: REGIONAL
Route53:
HostedZoneId: 'HOSTEDZONEID'
BasePath:
- /api
DefinitionBody:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location: !Sub 'open-api.yml'
我使用 Fn:Transform
来确保评估我的速记符号。我在我的 open-api.yml
中使用了一些 AWS API Gateway 扩展,如下所示:
...
x-amazon-apigateway-integration:
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${FunctionName}/invocations'
responses:
default:
statusCode: "200"
passthroughBehavior: "when_no_templates"
httpMethod: "GET"
type: "aws_proxy"
当我运行 sam deploy --debug
时,我收到以下错误:
Transform AWS::Include failed with: The specified S3 object's content should be valid Yaml/JSON
最佳答案
您收到此错误是因为您在 YAML 代码段中使用了速记符号。在撰写本文时,不支持通过 AWS::Include
转换包含的 YAML 片段的简写符号。
这意味着,而不是这个:
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${FunctionName}/invocations'
你必须这样做:
uri:
Fn::Sub:
- 'arn:aws:apigateway:${AWSRegion}:lambda:path/2015-03-31/functions/${FunctionArn}/invocations'
- AWSRegion:
Ref: AWS::Region
AWSAccountId:
Ref: AWS::AccountId
FunctionArn:
Fn::GetAtt: [UserServicesFunction, Arn]
见 AWS::Include transform了解更多信息。
关于amazon-web-services - 如何解决 SAM 模板中 "Transform AWS::Include failed with: The specified S3 object' 的内容应该是有效的 Yaml/JSON",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67178860/