Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.

Commit eeba84b

Browse files
committed
closes #84
1 parent b2fa77c commit eeba84b

4 files changed

Lines changed: 289 additions & 40 deletions

File tree

DEV.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,40 @@ $ regions=$(aws ec2 describe-regions --query "Regions[].RegionName" --output tex
1010

1111
### RegionMapAmazonLinux
1212

13+
Default user: ec2-user
14+
1315
```
14-
$ for region in $regions; do ami=$(aws --region $region ec2 describe-images --filters "Name=name,Values=amzn-ami-hvm-2017.03.1.20170812-x86_64-gp2" --query "Images[0].ImageId" --output "text"); printf "'$region':\n AMI: '$ami'\n"; done
16+
$ for region in $regions; do ami=$(aws --region $region ec2 describe-images --filters "Name=name,Values=amzn-ami-hvm-2017.09.1.20171120-x86_64-gp2" --query "Images[0].ImageId" --output "text"); printf "'$region':\n AMI: '$ami'\n"; done
1517
```
1618

1719
### RegionMapUbuntu
1820

21+
Default user: ubuntu
22+
1923
```
2024
$ for region in $regions; do ami=$(aws --region $region ec2 describe-images --filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20171208" --query "Images[0].ImageId" --output "text"); printf "'$region':\n AMI: '$ami'\n"; done
21-
```
25+
```
26+
27+
### RegionMapSUSELinuxEnterpriseServer
28+
29+
Default user: ec2-user
30+
31+
```
32+
$ for region in $regions; do ami=$(aws --region $region ec2 describe-images --filters "Name=name,Values=suse-sles-12-sp3-v20171212-hvm-ssd-x86_64" --query "Images[0].ImageId" --output "text"); printf "'$region':\n AMI: '$ami'\n"; done
33+
```
34+
35+
### RegionMapRHEL
36+
37+
Default user: ec2-user
38+
39+
```
40+
$ for region in $regions; do ami=$(aws --region $region ec2 describe-images --filters "Name=name,Values=RHEL-7.4_HVM_GA-20170808-x86_64-2-Hourly2-GP2" --query "Images[0].ImageId" --output "text"); printf "'$region':\n AMI: '$ami'\n"; done
41+
```
42+
43+
### RegionMapCentOS
44+
45+
Default user: centos
46+
47+
```
48+
$ for region in $regions; do ami=$(aws --region $region ec2 describe-images --filters "Name=name,Values=CentOS Linux 7 x86_64 HVM EBS 1708_11.01" --query "Images[0].ImageId" --output "text"); printf "'$region':\n AMI: '$ami'\n"; done
49+
```

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Manage AWS EC2 SSH access with IAM
22

3-
Use your IAM user's public SSH key to get access via SSH to an EC2 instance running **Amazon Linux** or **Ubuntu**. Depends on the [AWS CLI](https://aws.amazon.com/cli/) and `git` if you use the `install.sh` script.
3+
Use your IAM user's public SSH key to get access via SSH to an **EC2 instance** running
4+
* Amazon Linux 2017.09
5+
* Ubuntu 16.04
6+
* SUSE Linux Enterprise Server 12 SP3
7+
* RHEL 7.4
8+
* CentOS 7
9+
10+
`aws-ec2-ssh` depends on the [AWS CLI](https://aws.amazon.com/cli/) and `git` if you use the `install.sh` script.
411

512
## How does it work
613

showcase.yaml

Lines changed: 182 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,89 @@ Parameters:
2323
AllowedValues:
2424
- AmazonLinux
2525
- Ubuntu
26+
- SUSELinuxEnterpriseServer
27+
- RHEL
28+
- CentOS
2629
Mappings:
2730
OSMap:
2831
AmazonLinux:
2932
RegionMap: RegionMapAmazonLinux
33+
UserData: |
34+
/opt/aws/bin/cfn-init --verbose --stack=${STACKNAME} --region=${REGION} --resource=Instance
35+
/opt/aws/bin/cfn-signal --exit-code $? --stack=${STACKNAME} --region=${REGION} --resource=Instance
3036
Ubuntu:
3137
RegionMap: RegionMapUbuntu
38+
UserData: |
39+
bash -ex << "TRY"
40+
apt-get update
41+
apt-get -y install python-setuptools
42+
mkdir aws-cfn-bootstrap-latest
43+
curl -s -m 60 https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1
44+
easy_install aws-cfn-bootstrap-latest
45+
/usr/local/bin/cfn-init --verbose --stack=${STACKNAME} --region=${REGION} --resource=Instance
46+
TRY
47+
/usr/local/bin/cfn-signal --exit-code $? --stack=${STACKNAME} --region=${REGION} --resource=Instance
48+
SUSELinuxEnterpriseServer:
49+
RegionMap: RegionMapSUSELinuxEnterpriseServer
50+
UserData: |
51+
bash -ex << "TRY"
52+
mkdir aws-cfn-bootstrap-latest
53+
curl -s -m 60 https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1
54+
easy_install aws-cfn-bootstrap-latest
55+
/usr/bin/cfn-init --verbose --stack=${STACKNAME} --region=${REGION} --resource=Instance
56+
TRY
57+
/usr/bin/cfn-signal --exit-code $? --stack=${STACKNAME} --region=${REGION} --resource=Instance
58+
RHEL:
59+
RegionMap: RegionMapRHEL
60+
UserData: |
61+
bash -ex << "TRY"
62+
mkdir aws-cfn-bootstrap-latest
63+
curl -s -m 60 https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1
64+
easy_install aws-cfn-bootstrap-latest
65+
/bin/cfn-init --verbose --stack=${STACKNAME} --region=${REGION} --resource=Instance
66+
TRY
67+
/bin/cfn-signal --exit-code $? --stack=${STACKNAME} --region=${REGION} --resource=Instance
68+
CentOS:
69+
RegionMap: RegionMapCentOS
70+
UserData: |
71+
bash -ex << "TRY"
72+
mkdir aws-cfn-bootstrap-latest
73+
curl -s -m 60 https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1
74+
easy_install aws-cfn-bootstrap-latest
75+
/bin/cfn-init --verbose --stack=${STACKNAME} --region=${REGION} --resource=Instance
76+
TRY
77+
/bin/cfn-signal --exit-code $? --stack=${STACKNAME} --region=${REGION} --resource=Instance
3278
RegionMapAmazonLinux:
3379
'ap-south-1':
34-
AMI: 'ami-2ed19c41'
80+
AMI: 'ami-d5c18eba'
3581
'eu-west-3':
36-
AMI: 'ami-c8a017b5'
82+
AMI: 'ami-dd8b3ca0'
3783
'eu-west-2':
38-
AMI: 'ami-e3051987'
84+
AMI: 'ami-e7d6c983'
3985
'eu-west-1':
40-
AMI: 'ami-760aaa0f'
86+
AMI: 'ami-1a962263'
4187
'ap-northeast-2':
42-
AMI: 'ami-fc862292'
88+
AMI: 'ami-1196317f'
4389
'ap-northeast-1':
44-
AMI: 'ami-2803ac4e'
90+
AMI: 'ami-da9e2cbc'
4591
'sa-east-1':
46-
AMI: 'ami-1678037a'
92+
AMI: 'ami-286f2a44'
4793
'ca-central-1':
48-
AMI: 'ami-ef3b838b'
94+
AMI: 'ami-d29e25b6'
4995
'ap-southeast-1':
50-
AMI: 'ami-dd7935be'
96+
AMI: 'ami-c63d6aa5'
5197
'ap-southeast-2':
52-
AMI: 'ami-1a668878'
98+
AMI: 'ami-ff4ea59d'
5399
'eu-central-1':
54-
AMI: 'ami-e28d098d'
100+
AMI: 'ami-bf2ba8d0'
55101
'us-east-1':
56-
AMI: 'ami-6057e21a'
102+
AMI: 'ami-55ef662f'
57103
'us-east-2':
58-
AMI: 'ami-aa1b34cf'
104+
AMI: 'ami-15e9c770'
59105
'us-west-1':
60-
AMI: 'ami-1a033c7a'
106+
AMI: 'ami-a51f27c5'
61107
'us-west-2':
62-
AMI: 'ami-32d8124a'
108+
AMI: 'ami-bf4193c7'
63109
RegionMapUbuntu:
64110
'ap-south-1':
65111
AMI: 'ami-84dc94eb'
@@ -91,6 +137,93 @@ Mappings:
91137
AMI: 'ami-1a17137a'
92138
'us-west-2':
93139
AMI: 'ami-a2e544da'
140+
RegionMapSUSELinuxEnterpriseServer:
141+
'ap-south-1':
142+
AMI: 'ami-01b3fb6e'
143+
'eu-west-3':
144+
AMI: 'ami-865fe8fb'
145+
'eu-west-2':
146+
AMI: 'ami-1b51487f'
147+
'eu-west-1':
148+
AMI: 'ami-9628adef'
149+
'ap-northeast-2':
150+
AMI: 'ami-3a51f754'
151+
'ap-northeast-1':
152+
AMI: 'ami-d944c6bf'
153+
'sa-east-1':
154+
AMI: 'ami-c3682eaf'
155+
'ca-central-1':
156+
AMI: 'ami-4acd772e'
157+
'ap-southeast-1':
158+
AMI: 'ami-cf0262b3'
159+
'ap-southeast-2':
160+
AMI: 'ami-4caf592e'
161+
'eu-central-1':
162+
AMI: 'ami-00e06b6f'
163+
'us-east-1':
164+
AMI: 'ami-d4abc1ae'
165+
'us-east-2':
166+
AMI: 'ami-466f4723'
167+
'us-west-1':
168+
AMI: 'ami-f16b6f91'
169+
'us-west-2':
170+
AMI: 'ami-8368cefb'
171+
RegionMapRHEL:
172+
'ap-south-1':
173+
AMI: 'ami-e41b618b'
174+
'eu-west-3':
175+
AMI: 'ami-39902744'
176+
'eu-west-2':
177+
AMI: 'ami-a1f5e4c5'
178+
'eu-west-1':
179+
AMI: 'ami-bb9a6bc2'
180+
'ap-northeast-2':
181+
AMI: 'ami-0f5a8361'
182+
'ap-northeast-1':
183+
AMI: 'ami-30ef0556'
184+
'sa-east-1':
185+
AMI: 'ami-a789ffcb'
186+
'ca-central-1':
187+
AMI: 'ami-dad866be'
188+
'ap-southeast-1':
189+
AMI: 'ami-10bb2373'
190+
'ap-southeast-2':
191+
AMI: 'ami-ccecf5af'
192+
'eu-central-1':
193+
AMI: 'ami-d74be5b8'
194+
'us-east-1':
195+
AMI: 'ami-c998b6b2'
196+
'us-east-2':
197+
AMI: 'ami-cfdafaaa'
198+
'us-west-1':
199+
AMI: 'ami-66eec506'
200+
'us-west-2':
201+
AMI: 'ami-9fa343e7'
202+
RegionMapCentOS:
203+
'ap-south-1':
204+
AMI: 'ami-a691d8c9'
205+
'eu-west-2':
206+
AMI: 'ami-d5213fb1'
207+
'eu-west-1':
208+
AMI: 'ami-147fc16d'
209+
'ap-northeast-2':
210+
AMI: 'ami-56a40238'
211+
'ap-northeast-1':
212+
AMI: 'ami-1b27a37d'
213+
'sa-east-1':
214+
AMI: 'ami-284d0a44'
215+
'ca-central-1':
216+
AMI: 'ami-161ea572'
217+
'eu-central-1':
218+
AMI: 'ami-8f62ece0'
219+
'us-east-1':
220+
AMI: 'ami-95096eef'
221+
'us-east-2':
222+
AMI: 'ami-2d103948'
223+
'us-west-1':
224+
AMI: 'ami-c0bf85a0'
225+
'us-west-2':
226+
AMI: 'ami-02c71d7a'
94227
Conditions:
95228
UseCrossAccountIAM: !Not [!Equals [!Ref AssumeRole, '']]
96229
UseLocalIAM: !Equals [!Ref AssumeRole, '']
@@ -163,14 +296,35 @@ Resources:
163296
Type: AWS::EC2::Instance
164297
Metadata:
165298
'AWS::CloudFormation::Init':
166-
config:
167-
packages: !If
168-
- UseUbuntu
169-
- apt:
299+
configSets:
300+
default: [!Sub 'prepare${OS}', install]
301+
prepareAmazonLinux:
302+
packages:
303+
yum:
304+
git: []
305+
prepareUbuntu:
306+
packages:
307+
apt:
170308
git: []
171309
awscli: []
172-
- yum:
310+
prepareSUSELinuxEnterpriseServer: {}
311+
prepareRHEL:
312+
packages:
313+
rpm:
314+
epel: 'http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm'
315+
yum:
173316
git: []
317+
python2-pip: []
318+
python:
319+
awscli: []
320+
prepareCentOS:
321+
packages:
322+
rpm:
323+
epel: 'http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm'
324+
yum:
325+
git: []
326+
awscli: []
327+
install:
174328
files:
175329
'/opt/install.sh':
176330
source: 'https://raw.githubusercontent.com/widdix/aws-ec2-ssh/master/install.sh'
@@ -186,23 +340,14 @@ Resources:
186340
IamInstanceProfile: !Ref InstanceProfile
187341
InstanceType: 't2.micro'
188342
KeyName: !If [HasKeyName, !Ref KeyName, !Ref 'AWS::NoValue']
189-
UserData: !If
190-
- UseUbuntu
191-
- 'Fn::Base64': !Sub |
192-
#!/bin/bash -x
193-
bash -ex << "TRY"
194-
apt-get update
195-
apt-get -y install python-setuptools
196-
mkdir aws-cfn-bootstrap-latest
197-
curl -s -m 60 https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz | tar xz -C aws-cfn-bootstrap-latest --strip-components 1
198-
easy_install aws-cfn-bootstrap-latest
199-
/usr/local/bin/cfn-init --verbose --stack=${AWS::StackName} --region=${AWS::Region} --resource=Instance
200-
TRY
201-
/usr/local/bin/cfn-signal --exit-code $? --stack=${AWS::StackName} --region=${AWS::Region} --resource=Instance
202-
- 'Fn::Base64': !Sub |
203-
#!/bin/bash -x
204-
/opt/aws/bin/cfn-init --verbose --stack=${AWS::StackName} --region=${AWS::Region} --resource=Instance
205-
/opt/aws/bin/cfn-signal --exit-code $? --stack=${AWS::StackName} --region=${AWS::Region} --resource=Instance
343+
UserData:
344+
'Fn::Base64': !Sub
345+
- |
346+
#!/bin/bash -x
347+
export REGION=${AWS::Region}
348+
export STACKNAME=${AWS::StackName}
349+
${UserData}
350+
- UserData: !FindInMap [OSMap, !Ref OS, UserData]
206351
NetworkInterfaces:
207352
- AssociatePublicIpAddress: true
208353
DeleteOnTermination: true

0 commit comments

Comments
 (0)