-
Notifications
You must be signed in to change notification settings - Fork 19
01 common tools demo
Paul Duvall edited this page Jan 6, 2021
·
50 revisions
- Go to the AWS Cloud9 console and select Create environment.
- Enter a Name and Description (such as
#csoa-
and your intitials). - Select Next step.
- Select Create a new instance for environment (EC2).
- Select t2.micro.
- Leave the Cost-saving setting at the After 30-minute (default).
- Select Next step.
- Review best practices and select Create environment.
- Once your Cloud environment has been launched, open a new terminal in Cloud9.
- From your Cloud9 environment, go to Preferences (the gear icon).
- Scroll and choose AWS Settings.
- Deselect the toggle for AWS Managed temporary credentials.
- Sign in to the IAM console.
- In the navigation bar, choose Roles.
- Choose Create role.
- On the Select type of trusted entity page, with AWS service already chosen, for Choose the service that will use this role, choose EC2.
- For Select your use case, choose EC2.
- Choose Next: Permissions.
- On the Attach permissions policies page, in the list of policies, select the box next to AdministratorAccess, and then choose Next: Review.
- On the Review page, for Role Name, type a name for the role (for example
csoa-cloud9-instance-role
). - Choose Create Role.
- Sign in to the Amazon EC2 console.
- In the navigation bar, be sure the region selector displays the AWS Region that matches the one for your environment.
- Choose the Running Instances link or, in the navigation pane, expand Instances, and then choose Instances.
- In the list of instances, choose the instance with the Name that includes your environment name.
- Choose Actions, Security, Modify IAM Role.
- On the Modify IAM Role page, for IAM role, choose the name of the role you identified or that you created in the previous procedure, and then choose Save.
- Open a new terminal tab in your Cloud9 environment.
- Run the following commands:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Type the following to ensure that aws-cli/2.1x is installed.
aws --version
For more information, see Installing, updating, and uninstalling the AWS CLI version 2 on Linux.
From your AWS Cloud9 terminal, type the following to setup your directory structure:
mkdir ~/environment/csoa-1
aws s3 mb s3://csoa-1-$(aws sts get-caller-identity --output text --query 'Account')
cd ~/environment/csoa-1
Create empty source files:
touch buildspec.yml
touch csoa-1-cfn-nag-pipeline.yml
touch volume-encrypted.yml
touch volume.yml
- Copy the contents from buildspec.yml to your local buildspec.yml file in Cloud9 and save it.
- Copy the contents from volume.yml to your local volume.yml file in Cloud9 and save it.
- Copy the contents from volume-encrypted.yml to your local volume-encrypted.yml file in Cloud9 and save it.
- Copy the source contents from the csoa-1-cfn-nag-pipeline.yml file and save it to your local file in your Cloud9 environment called csoa-1-cfn-nag-pipeline.yml. This CloudFormation template provisions a deployment pipeline that runs preventive checks via cfn_nag.
cd ~/environment/csoa-1
zip csoa-1-examples.zip *.*
aws s3 sync ~/environment/csoa-1 s3://csoa-1-$(aws sts get-caller-identity --output text --query 'Account')
From your Cloud9 terminal, type the following (replacing you@example.com
):
aws cloudformation create-stack --stack-name csoa-1-cfn-nag-pipeline --template-body file:///home/ec2-user/environment/csoa-1/csoa-1-cfn-nag-pipeline.yml --parameters ParameterKey=EmailAddress,ParameterValue=you@example.com ParameterKey=CodeCommitS3Bucket,ParameterValue=csoa-1-$(aws sts get-caller-identity --output text --query 'Account') ParameterKey=CodeCommitS3Key,ParameterValue=csoa-1-examples.zip --capabilities CAPABILITY_NAMED_IAM --disable-rollback
It takes about 2 minutes to launch the pipeline and related resources in your AWS account.
From your Cloud9 terminal, type the following:
aws cloudformation describe-stacks --stack-name csoa-1-cfn-nag-pipeline
View the CodeCommit repo
- Go to the CloudFormation console to see the stack being launched.
- Once the CloudFormation stack is successful, select the checkbox next to the stack and click the Outputs tab.
- From Outputs, click on the PipelineUrl output to open the pipeline in AWS CodePipeline
- Go to the CodeCommit repo.
- Open
buildspec.yml
and change fromvolume.yml
tovolume-encrypted.yml
and commit the changes. - Go back to the pipeline you created and watch the change.
- In your Cloud9 environment, go to the csoa-1 directory and open each of the files to review the contents.
- Once finished reviewing, delete the CloudFormation stack with the command below.
aws cloudformation delete-stack --stack-name csoa-1-cfn-nag-pipeline
- Orchestrating a security incident response with AWS Step Functions
- Integrating AWS CloudFormation Guard into CI/CD pipelines
- Write preventive compliance rules for AWS CloudFormation templates the cfn-guard way
- Discovering sensitive data in AWS CodeCommit with AWS Lambda
- AWS CodePipeline supports deployments with CloudFormation StackSets
- Incorporating security in code-reviews using Amazon CodeGuru Reviewer