如何使用AWS CloudFormation在AWS API Gateway上应用安全策略?

时间:2019-09-04 05:33:22

标签: amazon-web-services amazon-cloudformation aws-api-gateway

我有一个简单的cloudformation模板,它正在为API网关创建自定义域,
该模板能够创建自定义域。

但是我找不到cloudformation属性来将Custom Domain Security Policy设置为TLS 1.2
该模板使用默认的TLS 1.0 Security Policy

创建一个自定义域

模板-

AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
Description: Test Custom Domain

Resources:
  test:
    Type: AWS::ApiGateway::DomainName
    Properties: 
      CertificateArn: !Sub 'arn:aws:acm:${AWS::Region}:${AWS::AccountId}:certificate/xxxx-xxx-xxx-xxxx-xxxx'
      DomainName: 'test-api.example.com'
      EndpointConfiguration: 
        Types: 
          - 'EDGE'

参考-
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html

2 个答案:

答案 0 :(得分:3)

很遗憾,此参数尚未通过CloudFormation公开。

这里有一张跟踪其进度的票-https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/3

目前,最好的选择是创建一个自定义CloudFormation资源。

此参数是通过API公开的,可以(至少部分)由其SDK使用-https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/apigateway.html#APIGateway.Client.create_domain_name

以下是讨论如何创建客户资源的文档-https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html

答案 1 :(得分:2)

在2020年7月添加了对指定Security Policy on an API Gateway domain的支持。AWS Docs提供了有关如何将此参数添加到CloudFormation模板的文档。安全策略的有效值为TLS_1_0TLS_1_2。下面的示例:

ApiCustomDomainName:
  Type: 'AWS::ApiGateway::DomainName'
  Condition: ApiGatewayEnabled
  Properties:
    DomainName: "example.com"
    RegionalCertificateArn: !Ref CertificateArn
    securityPolicy: "TLS_1_2"
      EndpointConfiguration:
        Types:
          - REGIONAL