json - 同一安全组的 CidrIp json 模板

标签 json amazon-web-services aws-cloudformation

我的 cloudformation 模板中有一个安全组:

"MySecurityGroup": {
   "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
            "GroupDescription": "Security Group",
            "SecurityGroupIngress": [
                {
                    "IpProtocol": "tcp",
                    "FromPort": "22",
                    "ToPort": "22",
                    "CidrIp": "0.0.0.0/0"
                }
             ]
         }
 }

我想将 0.0.0.0/0 动态更改为安全组 ID。我该怎么做?

最佳答案

我几乎完全明白了 Sanket 的建议。但它失败并出现以下错误:

Invalid id: "Semarchy-AppServerSecurityGroup-1AESXGUBKH5N4" (expecting "sg-...")

相反,这个替代方案正是我所需要的:

"InstanceSecurityGroup" : {
   "Type" : "AWS::EC2::SecurityGroup",
   "Properties" : {
      "GroupDescription" : "Security group for Semarchy MDM Instance",
      "VpcId" : { "Ref" : "VpcId" },
      "SecurityGroupIngress" : [ {
        "IpProtocol" : "tcp", 
        "FromPort" :   "1521", 
        "ToPort" :     "1521", 
        "SourceSecurityGroupId" : { "Fn::GetAtt" : [ "AppServerSecurityGroup", "GroupId" ] } 
      } ]
   }
}

关于json - 同一安全组的 CidrIp json 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20708313/

相关文章:

amazon-web-services - 使用 AWS Go 开发工具包的动态 list

amazon-web-services - 在不使用 CNAME 的情况下将 Route53 中的子域指向 CloudFront

amazon-web-services - 如何在cloudformation中获取Elastic Beanstalk EC2实例的instanceId?

amazon-web-services - Terraform - 使用 CloudFormation 功能接收错误

json - 语法错误: Unexpected token v in JSON at position 0

javascript - Highcharts - 饼图动态更改切片颜色

c# - 我如何提取 Paypal 响应 C#

amazon-web-services - Azure Web 应用程序和 Azure ad http 错误 500.79 内部服务器错误

amazon-web-services - 在 AWS Cloudformation 中使用最新的启动模板版本

json - 使用查询在 Golang 中处理 API?