Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/create-ec2-machine-database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
DEVICENAME='/dev/sdb'
IMAGEID='ami-7f43f307'
INSTANCETYPE='t2.micro'
INSTANCEPROFILE='s3access-profile'
KEYNAME='hackoregon-2018-database-dev-env'
REGION='us-west-2'
SECURITYGROUPIDS='sg-28154957'
Expand All @@ -24,6 +25,7 @@ aws ec2 run-instances \
--image-id $IMAGEID \
--count 1 \
--instance-type $INSTANCETYPE \
--iam-instance-profile Name=$INSTANCEPROFILE \
--key-name $KEYNAME \
--security-group-ids $SECURITYGROUPIDS \
--subnet-id $SUBNETID\
Expand Down
32 changes: 32 additions & 0 deletions bin/create-instance-profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -e

ROLE_NAME='s3access'
TRUST_POLICY_FILE='file://ec2-role-trust-policy.json'
ACCESS_POLICY_FILE='file://ec2-role-access-policy.json'
ACCESS_POLICY_NAME='S3-Permissions'
INSTANCE_PROFILE_NAME='s3access-profile'

echo
echo "Creating IAM role named \"$ROLE_NAME\""
aws iam create-role \
--role-name $ROLE_NAME \
--assume-role-policy-document $TRUST_POLICY_FILE

echo
echo "Attaching the access policy \"$ACCESS_POLICY_FILE\" to role \"$ROLE_NAME\" "
aws iam put-role-policy \
--role-name $ROLE_NAME \
--policy-name $ACCESS_POLICY_NAME \
--policy-document $ACCESS_POLICY_FILE

echo
echo "Creating an instance profile named \"$INSTANCE_PROFILE_NAME\" "
aws iam create-instance-profile \
--instance-profile-name $INSTANCE_PROFILE_NAME

echo
echo "Adding the role named \"$ROLE_NAME\" to the instance profile named \"$INSTANCE_PROFILE_NAME\" "
aws iam add-role-to-instance-profile \
--instance-profile-name $INSTANCE_PROFILE_NAME \
--role-name $ROLE_NAME

10 changes: 10 additions & 0 deletions bin/ec2-role-access-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:*"],
"Resource": ["*"]
}
]
}
10 changes: 10 additions & 0 deletions bin/ec2-role-trust-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "ec2.amazonaws.com"},
"Action": "sts:AssumeRole"
}
]
}