在云形成中为SQS创建VPC接口端点

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

我想知道是否可以在我的CloudFormation文件中创建一个资源来为SQS创建一个VPC端点。我能够为SQS和DynamoDB做到这一点,但我相信这是因为它们是网关端点。

现在我已将我的SQS资源定义为:

SQSEndpoint:
    Type: AWS::EC2::VPCEndpoint
    Properties:
      PolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Principal: '*'
            Action:
              - 'sqs:*'
            Resource:
              - '*'
      ServiceName: !Join 
        - ''
        - - com.amazonaws.
          - !Ref 'AWS::Region'
          - .sqs
      SubnetIds:
        - !Ref PrivateSubnet
        - !Ref PublicSubnet
      VpcId: !Ref 'VPC'
      VpcEndpointType: Interface

但是,当我尝试创建堆栈时,我收到错误:

enter image description here

看起来有可能从AWS中读取this blog post。虽然我找不到任何示例或文档。有任何想法吗?

amazon-web-services amazon-cloudformation amazon-vpc
1个回答
0
投票

我想通了,对于使用Gateway Endpoints的DynamoDB和S3,必须定义PolicyDocument属性。对于所有其他服务,不需要定义。因此,对于SQS,所需要的只是:

 SQSEndpoint:
    Type: AWS::EC2::VPCEndpoint
    Properties:
      ServiceName: !Join 
        - ''
        - - com.amazonaws.
          - !Ref 'AWS::Region'
          - .sqs
      SubnetIds:
        - !Ref PrivateSubnet
        - !Ref PublicSubnet
      VpcId: !Ref 'VPC'
      VpcEndpointType: Interface

编辑:仍然没有工作,即使设置了接口端点,我不得不:

  1. PrivateDnsEnabled属性设置为true,以便您可以使用AWS CLI,因为AWS CLI使用公共端点,并且设置PrivateDnsEnabled允许私有端点自动映射到公共端点
  2. SecurityGroupsIds设置为允许来自您的VPC的入站流量的安全组。如果设置此实例,则使用默认安全组,它仅允许来自具有默认安全组的源的入站流量,这意味着SQS将无法将流量发送回您的实例

总而言之:

  SQSEndpoint:
    Type: AWS::EC2::VPCEndpoint
    Properties:
      ServiceName: !Join 
        - ''
        - - com.amazonaws.
          - !Ref 'AWS::Region'
          - .sqs
      SubnetIds:
        - !Ref PrivateSubnet
      VpcId: !Ref 'VPC'
      VpcEndpointType: Interface
      SecurityGroupIds:
        - !Ref PrivateSubnetInstanceSG # has to allow traffic from your VPC
      PrivateDnsEnabled: true
© www.soinside.com 2019 - 2024. All rights reserved.