1+ AWSTemplateFormatVersion : ' 2010-09-09'
2+ Description : FormKiQ OpenSearch Bastion SSH Tunnel Host
3+
4+ Parameters :
5+
6+ KeyPairName :
7+ Type : AWS::EC2::KeyPair::KeyName
8+ Description : Name of an existing public/private key pair, which allows you
9+ to securely connect to your instance after it launches.
10+
11+ LatestAmiId :
12+ Type : ' AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
13+ Default : ' /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
14+
15+ VpcStackName :
16+ Type : String
17+ Description : The name of the FormKiQ VPC Stack Name
18+ AllowedPattern : " .+"
19+
20+ VpcSubnets :
21+ Description : " SubnetId in VPC"
22+ Type : " List<AWS::EC2::Subnet::Id>"
23+
24+ Resources :
25+
26+ BastionHost :
27+ Type : ' AWS::EC2::Instance'
28+ Properties :
29+ InstanceType : t3.micro
30+ ImageId :
31+ Ref : LatestAmiId
32+ IamInstanceProfile :
33+ Ref : BastionHostInstanceProfile
34+ KeyName :
35+ Ref : KeyPairName
36+ SecurityGroupIds :
37+ - Ref : BastionSecurityGroup
38+ SubnetId :
39+ Fn::Join :
40+ - " ,"
41+ - Ref : VpcSubnets
42+ UserData :
43+ Fn::Base64 :
44+ Fn::Sub : |
45+ # !/bin/bash
46+ sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
47+ Tags :
48+ - Key : Name
49+ Value :
50+ Fn::Sub : " Bastion Host"
51+ - Key : StackName
52+ Value :
53+ Fn::Sub : " ${AWS::StackName}"
54+
55+ BastionSecurityGroup :
56+ Type : AWS::EC2::SecurityGroup
57+ Properties :
58+ GroupDescription : Allow SSH/OpenSearch Tunnel traffic
59+ VpcId :
60+ Fn::ImportValue :
61+ Fn::Sub : ' ${VpcStackName}-Vpc'
62+ SecurityGroupIngress :
63+ - IpProtocol : tcp
64+ FromPort : ' 22'
65+ ToPort : ' 22'
66+ CidrIp : 50.71.0.58/32
67+ Description : SSH Port
68+ - IpProtocol : tcp
69+ FromPort : ' 8157'
70+ ToPort : ' 8157'
71+ CidrIp : 50.71.0.58/32
72+ Description : OpenSearch Tunnel Port
73+ Tags :
74+ - Key : StackName
75+ Value :
76+ Fn::Sub : " ${AWS::StackName}"
77+
78+ BastionHostInstanceProfile :
79+ Type : AWS::IAM::InstanceProfile
80+ Properties :
81+ Path : ' /'
82+ Roles :
83+ - Ref : BastionHostRole
84+
85+ BastionHostRole :
86+ Type : ' AWS::IAM::Role'
87+ Properties :
88+ AssumeRolePolicyDocument :
89+ Version : ' 2012-10-17'
90+ Statement :
91+ - Effect : Allow
92+ Principal :
93+ Service : ec2.amazonaws.com
94+ Action : ' sts:AssumeRole'
95+ Path : " /"
96+ ManagedPolicyArns :
97+ - ' arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore'
98+ - ' arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy'
99+ Tags :
100+ - Key : StackName
101+ Value :
102+ Fn::Sub : " ${AWS::StackName}"
103+
104+ Outputs :
105+ BastionHostId :
106+ Description : Bastion Host Id
107+ Value :
108+ Ref : BastionHost
109+ BastionPublicDnsName :
110+ Description : Bastion Public Dns
111+ Value :
112+ Fn::GetAtt :
113+ - BastionHost
114+ - PublicDnsName
115+ BastionPublicIp :
116+ Description : Bastion Public Ip
117+ Value :
118+ Fn::GetAtt :
119+ - BastionHost
120+ - PublicIp
0 commit comments