-
Notifications
You must be signed in to change notification settings - Fork 4
Launch EC2 instance with CloudFormation #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
khashf
wants to merge
11
commits into
master
Choose a base branch
from
create-infra-with-cf
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
12438fe
Change instance's volume size to a variable
khashf 58f334c
Update: Make instance's volume type a variable loaded from file
khashf 6e8ea8e
Update: DeleteOnTermination becomes a variable loaded from file
khashf ab1c7c6
Improve comment around $EC2PROFILE loading
khashf 776f899
Definitely do *not* want to lose the databases
MikeTheCanuck 75b42aa
Add CloudFormation template
khashf 1da6dc8
Roll back 2 intentionally file changes
khashf 83920cd
Update policy that limit access only to a certain s3 bucket
khashf a3b76e2
Update: Persist Block Device after instance Termination
khashf d80952c
Separate IAM Role away from EC2 instance launching
khashf caf9dc8
Rename directory
khashf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # Itention: | ||
| # Create a ec2 instance that has read permission to the existing s3 instance(s) | ||
|
|
||
| # USAGE: | ||
| # Run: | ||
| # aws cloudformation create-stack --stack-name <stack name here> --template-body file:///absolute/path/to/this-file.yaml --capabilities CAPABILITY_NAMED_IAM | ||
|
|
||
| # TODO: | ||
| # - separate parameters into a file | ||
| # - write wrapper for the aws cli command | ||
|
|
||
|
|
||
| --- | ||
| AWSTemplateFormatVersion: '2010-09-09' | ||
| Description: 'AWS CloudFormation to create a ec2 instance that has read permission to the existing s3 instance(s)' | ||
|
|
||
| Parameters: | ||
|
|
||
| InstanceType: | ||
| Description: Instance type used to build the machine(s) | ||
| Type: String | ||
| Default: t2.micro | ||
|
|
||
| ImageId: | ||
| Description: AMI ID used to build the machine(s) | ||
| Type: String | ||
| Default: ami-7f43f307 | ||
|
|
||
| AvailabilityZone: | ||
| Description: Avalaibility Zone to deploy within (different than region) | ||
| Type: String | ||
| Default: us-west-2a | ||
|
|
||
| SubnetId: | ||
| Description: Subnet's ID to be located at | ||
| Type: String | ||
| Default: subnet-8794fddf | ||
|
|
||
| SecurityGroupId: | ||
| Description: The Security Groups to use for the EC2 hosts | ||
| Type: String | ||
| Default: sg-28154957 | ||
|
|
||
| Resources: | ||
|
|
||
| DBInstance: | ||
| Type: AWS::EC2::Instance | ||
| Properties: | ||
| InstanceType: t2.micro # !Ref InstanceType | ||
| ImageId: ami-7f43f307 # !Ref ImageId | ||
| SecurityGroupIds: | ||
| - | ||
| sg-28154957 # !Ref SecurityGroupId | ||
| AvailabilityZone: us-west-2a # !Ref AvailabilityZone | ||
| SubnetId: subnet-8794fddf # !Ref SubnetId | ||
| IamInstanceProfile: | ||
| !Ref InstanceProfile | ||
| BlockDeviceMappings: | ||
| - | ||
| DeviceName: /dev/sdb # !Ref DeviceName | ||
| Ebs: | ||
| VolumeType: gp2 # !Ref VolumeType | ||
| VolumeSize: 8 # !Ref VolumeSize | ||
| DeleteOnTermination: True # False # !Ref DeleteOnTermination | ||
| KeyName: hackoregon-2018-database-dev-env # !Ref KeyName | ||
| Tags: | ||
| - | ||
| Key: Name | ||
| Value: DB # !Ref InstanceName | ||
|
|
||
| Role: | ||
| Type: AWS::IAM::Role | ||
| Properties: | ||
| RoleName: db-role | ||
| AssumeRolePolicyDocument: | ||
| Version: '2012-10-17' | ||
| Statement: | ||
| - Effect: Allow | ||
| Principal: | ||
| Service: | ||
| - ec2.amazonaws.com | ||
| Action: | ||
| - sts:AssumeRole | ||
| Path: "/" | ||
| #Policies: | ||
| # - !Ref RolePolicies | ||
|
|
||
| RolePolicies: | ||
| Type: AWS::IAM::Policy | ||
| Properties: | ||
| PolicyName: ec2-read-s3-policy | ||
| PolicyDocument: | ||
| Version: '2012-10-17' | ||
| Statement: | ||
| - Effect: Allow | ||
| Action: | ||
| - "s3:GetObject" | ||
| - "s3:ListBucket" | ||
| Resource: "*" | ||
| Roles: | ||
| - !Ref Role | ||
|
|
||
| InstanceProfile: | ||
| Type: AWS::IAM::InstanceProfile | ||
| Properties: | ||
| Path: "/" | ||
| Roles: | ||
| - !Ref Role | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing policy is slightly different and limited to only one bucket:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "s3:*", "Resource": [ "arn:aws:s3:::hacko-data-archive/*" ] } ] }Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @DingoEatingFuzz . Yes, I was aware of this. I wasn't sure which bucket to select so I left it a wildcard for easier testing. Patches incoming in a few mins
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DingoEatingFuzz : Updated.
Is it ok if I limit the allowed actions to the 2 following ones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially. Depends on whether or not the box will also be writing back to the bucket. I defer to @MikeTheCanuck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now let's just leave it as read-only, but be prepared to generate a similar policy for whatever strategy we happen to use for backups. I'm conflicted on whether backups would be appropriate to write to the
hacko-data-archivebucket, otherwise no reason I can think of to open it for writes.