Cloudformation API GW IntegrationResponseres响应头信息

问题描述 投票:0回答:1

可以在ResponseParameter中使用 !Ref到一个S3 bucket。 例如,我使用了一个资源AWS::S3::Bucket。

IntegrationResponses:
      - ResponseParameters:
          method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
          method.response.header.Access-Control-Allow-Methods: "'POST,OPTIONS'"
          method.response.header.Access-Control-Allow-Origin: "'https://dynamicbucketname.s3-us-west-2.amazonaws.com'"
          method.response.header.Access-Control-Allow-Credentials: "'true'"

S3Bucket:
 Type: AWS::S3::Bucket
 Properties:
   PublicAccessBlockConfiguration:
     BlockPublicAcls: true
     IgnorePublicAcls: false
     BlockPublicPolicy: true
     RestrictPublicBuckets: true  
   WebsiteConfiguration:
     IndexDocument: index.html
     ErrorDocument: error.html

所以本质上我使用的是AWS::S3::Bucket这个资源 它允许模板来创建这个桶 因此,名称将是动态的。 我希望能够在Origin中引用S3Bucket。 这可能吗? 我知道它可以是静态的,比如"''。https:/www.example.com'"

amazon-cloudformation aws-api-gateway
1个回答
1
投票

一种方法是如下所示,使用 子公司 函数。

可以在ResponseParameter中使用 !"Ref "到S3 bucket。比如说

IntegrationResponses:
      - ResponseParameters:
          method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
          method.response.header.Access-Control-Allow-Methods: "'POST,OPTIONS'"
          method.response.header.Access-Control-Allow-Origin: !Sub "'https://${S3Bucket.DomainName}'"
          method.response.header.Access-Control-Allow-Credentials: "'true'"

Other Bucket 返回值比 DomainName 被列入 此处:

© www.soinside.com 2019 - 2024. All rights reserved.