0% found this document useful (0 votes)
71 views4 pages

Lab 5 Storage

This document provides instructions for a lab exercise to create an S3 bucket for storing employee photos, modify an EC2 instance to use that S3 bucket, and then stop the EC2 instance to avoid costs. The steps include creating an S3 bucket, uploading an object, modifying the bucket policy, modifying the EC2 user data to reference the S3 bucket, launching the EC2 instance, and stopping the instance once complete.

Uploaded by

Alaa Barazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views4 pages

Lab 5 Storage

This document provides instructions for a lab exercise to create an S3 bucket for storing employee photos, modify an EC2 instance to use that S3 bucket, and then stop the EC2 instance to avoid costs. The steps include creating an S3 bucket, uploading an object, modifying the bucket policy, modifying the EC2 user data to reference the S3 bucket, launching the EC2 instance, and stopping the instance once complete.

Uploaded by

Alaa Barazi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

02/10/2021, 15:17 lab-5-storage

[version_1.0]
©2021 Amazon Web Services, Inc. and its affiliates. All rights reserved. This work may not be
reproduced or redistributed, in whole or in part, without prior written permission from Amazon
Web Services, Inc. Commercial copying, lending, or selling is prohibited.
Errors or corrections? Contact us at https://support.aws.amazon.com/#/contacts/aws-training

Exercise: Storage
The exercises are designed to be completed in your AWS account, and will have an associated cost.
For this reason, in addition to the written instructions, this course includes video recordings of the
exercises. If you intend to attempt the exercises, familiarize yourself with AWS pricing, specifically
Amazon EC2 pricing, Amazon S3 pricing, and Amazon DynamoDB pricing and the AWS Free Tier.
For this scenario, you will create the S3 bucket where the employee photos will be housed. You
will also update the EC2 User Data to use the S3 bucket you create.
In this exercise, you will create a S3 bucket and upload some objects. Then, you will modify the
bucket policy and launch an EC2 instance. Finally, you will stop the EC2 instance to prevent future
costs.

Lab Steps
Stage 1 - Create an S3 bucket
1. Search for S3 in the search bar at the top. Choose S3.
2. Choose Create bucket.
3. For the Bucket name name it employee-photo-bucket- then use your initials and a unique
number.
Example:

employee-photo-bucket-al-007

4. Make sure the Region is the region where you have created the other services. Again, this
can be found at the top right.
5. Choose Create bucket.

Stage 2 - Upload a photo


1. Choose your newly created bucket by clicking on the name of your bucket.
2. Choose Upload.
3. Choose Add files. Choose a photo of your choice on your computer.
4. Choose Upload.
5. At the top, you should see Upload succeeded in green. Choose Exit.

Stage 3 - Modify the S3 bucket policy


1. Choose the Permissions tab. Scroll down to Bucket policy.
2. Choose Edit. Paste in the following policy:

https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-GCNv2/lab-5-storage.html 1/4
02/10/2021, 15:17 lab-5-storage
{
   "Version": "2012-10-17",
   "Statement": [
      {
           "Sid": "AllowS3ReadAccess",
           "Effect": "Allow",
           "Principal": {
               "AWS": "arn:aws:iam::<INSERT-ACCOUNT-
NUMBER>:role/S3DynamoDBFullAccessRole"
          },
           "Action": "s3:*",
           "Resource": [
               "arn:aws:s3:::<INSERT-BUCKET-NAME>",
               "arn:aws:s3:::<INSERT-BUCKET-NAME>/*"
          ]
      }
  ]
}

3. Replace the <INSERT-BUCKET-NAME> value with your bucket name.


4. Replace the <INSERT-ACCOUNT-NUMBER> value with your account number. This can be found
by choosing your username at the top right and copying down the value next to My Account.
Example:

{
   "Version": "2012-10-17",
   "Statement": [
      {
           "Sid": "AllowS3ReadAccess",
           "Effect": "Allow",
           "Principal": {
               "AWS":
"arn:aws:iam::000000000000:role/S3DynamoDBFullAccessRole"
          },
           "Action": "s3:*",
           "Resource": [
               "arn:aws:s3:::employee-photo-bucket-al-007",
               "arn:aws:s3:::employee-photo-bucket-al-007/*"
          ]
      }
  ]
}

5. Choose Save changes.

Stage 4 - Modify the application to use the S3 bucket


1. Search for EC2 in the search bar at the top. Choose EC2.
2. Choose Instances under Instances at the left side panel.
3. Select the employee-directory-app instance. Which should be in the Stopped state.
4. Choose Actions. Image and templates and Launch more like this.
5. At the top, choose 3. Configure instance.
6. Next to Auto-assign Public IP, choose Enable.

https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-GCNv2/lab-5-storage.html 2/4
02/10/2021, 15:17 lab-5-storage

7. Scroll down to Advanced Details. And next to User data. You will update the
PHOTOS_BUCKET and AWS_DEFAULT_REGION variable.

#!/bin/bash -ex
wget https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-
GCNv2/FlaskApp.zip
unzip FlaskApp.zip
cd FlaskApp/
yum -y install python3 mysql
pip3 install -r requirements.txt
amazon-linux-extras install epel
yum -y install stress
export PHOTOS_BUCKET=<INSERT-BUCKET-NAME-HERE>
export AWS_DEFAULT_REGION=<INSERT-REGION-NAME-HERE>
export DYNAMO_MODE=on
FLASK_APP=application.py /usr/local/bin/flask run --host=0.0.0.0 --port=80

Change the following line to match your bucket name:


Example:

export PHOTOS_BUCKET=employee-photo-bucket-al-007

8. Choose 5. Add Tags at the top. Append s3 to the Value.


Example:

employee-directory-app-s3

9. Choose Review and Launch. Choose Launch.


10. Leave the app-key-pair selected under Select a key pair. Select the acknowledgement.
11. Choose Launch Instances.
12. Choose View Instances. The instance should now show up under Instances. Wait for the
Instance state to change to Running and the Status check to change to green.
13. Next to Name, choose the checkbox to select the employee-directory-app-s3 instance.
Under the Details tab copy down the Public IPv4 address.
Note: Do not use the link to open the IPv4 address. Instead, copy only the address and paste it into
a new browser.
14. Paste it into a new browser tab/window. You should see a Employee Directory placeholder.
Right now you will not be able to interact with it as it's not currently connected to the
database.

Stage 5 - Delete your object


1. Search for S3 in the search bar at the top. Choose S3.
2. Select your employee-photo-bucket- . Select your object.
3. Choose Delete. Confirm deletion by typing in the words permanently delete.
4. Choose Delete objects. Choose Exit.

Stage 6 - Stop your EC2 instance

https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-GCNv2/lab-5-storage.html 3/4
02/10/2021, 15:17 lab-5-storage

Congrats! You've launched an EC2 instance that uses the S3 bucket you created. To prevent future
costs, you will now stop the instance. (Note: do not terminate it, as the next lab will use this
instance.)
1. Search for EC2 in the search bar at the top. Choose EC2.
2. Choose Instances in the left side panel and select the employee-directory-app-s3 .
3. Choose Instance state and Stop instance. Choose Stop. The Instance state will eventually
go into the Stopped state.

Lab Complete
Congratulations! You have completed the lab.
For feedback, suggestions, or corrections, please contact us at:https://support.aws.amazon.co
m/#/contacts/aws-training

https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-GCNv2/lab-5-storage.html 4/4

You might also like