1+ AWSTemplateFormatVersion : ' 2010-09-09'
2+ Parameters :
3+ ExistingSecurityGroups :
4+ Type : List<AWS::EC2::SecurityGroup::Id>
5+ ExistingVPC :
6+ Type : AWS::EC2::VPC::Id
7+ Description : The VPC ID that includes the security groups in the ExistingSecurityGroups
8+ parameter.
9+ InstanceType :
10+ Type : String
11+ Default : t2.micro
12+ AllowedValues :
13+ - t2.micro
14+ - m1.small
15+ Mappings :
16+ AWSInstanceType2Arch :
17+ t2.micro :
18+ Arch : HVM64
19+ m1.small :
20+ Arch : HVM64
21+
22+ AWSRegionArch2AMI :
23+ us-east-1 :
24+ HVM64 : ami-0ff8a91507f77f867
25+ HVMG2 : ami-0a584ac55a7631c0c
26+ us-west-2 :
27+ HVM64 : ami-a0cfeed8
28+ HVMG2 : ami-0e09505bc235aa82d
29+ us-west-1 :
30+ HVM64 : ami-0bdb828fd58c52235
31+ HVMG2 : ami-066ee5fd4a9ef77f1
32+ eu-west-1 :
33+ HVM64 : ami-047bb4163c506cd98
34+ HVMG2 : ami-0a7c483d527806435
35+ eu-central-1 :
36+ HVM64 : ami-0233214e13e500f77
37+ HVMG2 : ami-06223d46a6d0661c7
38+ ap-northeast-1 :
39+ HVM64 : ami-06cd52961ce9f0d85
40+ HVMG2 : ami-053cdd503598e4a9d
41+ ap-southeast-1 :
42+ HVM64 : ami-08569b978cc4dfa10
43+ HVMG2 : ami-0be9df32ae9f92309
44+ ap-southeast-2 :
45+ HVM64 : ami-09b42976632b27e9b
46+ HVMG2 : ami-0a9ce9fecc3d1daf8
47+ sa-east-1 :
48+ HVM64 : ami-07b14488da8ea02a0
49+ HVMG2 : NOT_SUPPORTED
50+ cn-north-1 :
51+ HVM64 : ami-0a4eaf6c4454eda75
52+ HVMG2 : NOT_SUPPORTED
53+ Resources :
54+ SecurityGroup :
55+ Type : AWS::EC2::SecurityGroup
56+ Properties :
57+ GroupDescription : Allow HTTP traffic to the host
58+ VpcId :
59+ Ref : ExistingVPC
60+ SecurityGroupIngress :
61+ - IpProtocol : tcp
62+ FromPort : ' 80'
63+ ToPort : ' 80'
64+ CidrIp : 0.0.0.0/0
65+ SecurityGroupEgress :
66+ - IpProtocol : tcp
67+ FromPort : ' 80'
68+ ToPort : ' 80'
69+ CidrIp : 0.0.0.0/0
70+ AllSecurityGroups :
71+ Type : Custom::Split
72+ Properties :
73+ ServiceToken : !GetAtt AppendItemToListFunction.Arn
74+ List :
75+ Ref : ExistingSecurityGroups
76+ AppendedItem :
77+ Ref : SecurityGroup
78+ AppendItemToListFunction :
79+ Type : AWS::Lambda::Function
80+ Properties :
81+ Handler : index.handler
82+ Role : !GetAtt LambdaExecutionRole.Arn
83+ Code :
84+ ZipFile : !Sub |
85+ var response = require('cfn-response');
86+ exports.handler = function(event, context) {
87+ var responseData = {Value: event.ResourceProperties.List};
88+ responseData.Value.push(event.ResourceProperties.AppendedItem);
89+ response.send(event, context, response.SUCCESS, responseData);
90+ };
91+ Runtime : nodejs8.10
92+ MyEC2Instance :
93+ Type : AWS::EC2::Instance
94+ Properties :
95+ ImageId :
96+ Fn::FindInMap :
97+ - AWSRegionArch2AMI
98+ - Ref : AWS::Region
99+ - Fn::FindInMap :
100+ - AWSInstanceType2Arch
101+ - Ref : InstanceType
102+ - Arch
103+ SecurityGroupIds : !GetAtt AllSecurityGroups.Value
104+ InstanceType :
105+ Ref : InstanceType
106+ LambdaExecutionRole :
107+ Type : AWS::IAM::Role
108+ Properties :
109+ AssumeRolePolicyDocument :
110+ Version : ' 2012-10-17'
111+ Statement :
112+ - Effect : Allow
113+ Principal :
114+ Service :
115+ - lambda.amazonaws.com
116+ Action :
117+ - sts:AssumeRole
118+ Path : " /"
119+ Policies :
120+ - PolicyName : root
121+ PolicyDocument :
122+ Version : ' 2012-10-17'
123+ Statement :
124+ - Effect : Allow
125+ Action :
126+ - logs:*
127+ Resource : arn:aws:logs:*:*:*
128+ Outputs :
129+ AllSecurityGroups :
130+ Description : Security Groups that are associated with the EC2 instance
131+ Value :
132+ Fn::Join :
133+ - " , "
134+ - Fn::GetAtt :
135+ - AllSecurityGroups
136+ - Value
0 commit comments