Step1: Setting Up Development Environment
Step1: Setting Up Development Environment
Create an Environment
In this step, you use AWS Cloud9 console to create and then open an AWS Cloud9
development environment.
Note
Note
Choosing instance types with more RAM and vCPUs might result in additional
charges to your AWS account for Amazon EC2.
9. For Platform, choose the type of Amazon EC2 instance that AWS Cloud9 will create
and then connect to this environment: Amazon Linux or Ubuntu.
If you're not sure what to choose, we recommend that you skip ahead to step 12 in
this procedure.
When you skip past Network settings (advanced) and leave the preselected default
settings, AWS Cloud9 attempts to automatically use the default VPC with its single
subnet in the same AWS account and AWS Region as the new environment.
12. For more information, see VPC Settings for AWS Cloud9 Development
Environments.
13. For Cost-saving setting, choose the amount of time until AWS Cloud9 shuts down
the Amazon EC2 instance for the environment after all web browser instances that are
connect to the IDE for the environment have been closed. Or leave the default choice.
Note
Choosing a shorter time period might result in fewer charges to your AWS
account. Likewise, choosing a longer time might result in more charges.
After your environment is created, the AWS Cloud9 IDE is displayed. You'll learn about the
AWS Cloud9 IDE in the next step.
If AWS Cloud9 doesn't display the IDE after at least five minutes, there might be a problem
with your web browser, your AWS access permissions, the instance, or the associated virtual
private cloud (VPC). For possible fixes, see Cannot Open an
Environment in Troubleshooting.
3. Next, download files for front-end react code and run the below command
o wget https://testorlando1.s3.amazonaws.com/VodAws.zip
6. We will now be installing the development tools using the Node Package
Manager(NPM)
7. Install the node modules, run below command in your VodAws directory
o npm install
1. Make sure you are in the root folder of our project which is VodAws directory.
2. Next we are going to begin development of our Amplify project by using the
initialization command. This command creates new AWS backend resources
(in this case a single S3 bucket to host your CloudFormation templates) and
pulls the AWS service configurations into the app!
o amplify init
Note: It is recommended to run this command from the root of your app directory
4. Now, we are going to add the amplify api module to the project. Run the below
command.
o amplify add api
o Go to the output tabs and copy these values of the below variables in a
notepad, we will use this further in our workshop.
o AuthRoleArn
o AuthRoleName
o DeploymentBucketName
o UnAuthRoleName
o UnAuthRoleArn
10. Now click on the nested cloudformation stack which would be named similar to this
“amplify-vodaws-prod-******-authvodaws******” as shown in below screenshot.
o Go to the output tabs and copy these values of the below variables in a
notepad, we will use this further in our workshop.
o AppClientID
o AppClientIDWeb
o IdentityPoolID
o UserPoolID
Important:
IAM users can't create CloudFront key pairs. You must log in using root credentials to
create key pairs.
1. Sign in to the AWS Management Console using the root credentials for an
AWS account.
Important
Save the private key for your CloudFront key pair in a secure location, and set
permissions on the file so that only the desired administrator users can read it.
If someone gets your private key, they can generate valid signed URLs and
signed cookies and download your content. You cannot get the private key
again, so if you lose or delete it, you must create a new CloudFront key pair.
8. Record the key pair ID for your key pair in a notepad. (In the AWS
Management Console, this is called the access key ID.) You'll use it when you
create signed URLs or signed cookies.
For more information on generating CloudFront key pairs please follow this
document:
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-
content-trusted-signers.html#private-content-creating-cloudfront-key-pairs
1. We need to store the private key file on our Cloud9 ec2 instance.
a. Copy the entire content of private key file you just downloaded.
i. To copy, you can open the file in your terminal/command prompt and
copy the entire content of the file including,
1. Run the following command to store the secret key in secrets manager. Make sure
your under “ /home/ec2-user/environment“ directory.
a. aws secretsmanager create-secret --name VodAws --secret-binary
file://privateKey.pem
2. Copy the values of Secret Key Name and ARN value from the response of the above
command in a notepad.
1. Make sure you have the values of the below variables in your notepad.
1. Download this zip file on your local system and extract the contents.
3. Make sure you have “vod-helpers” folder in your s3 bucket and then make it public
by selecting the folder and clicking on Actions drop down button.
5.
6. Before deploying this cloudformation template make sure you are in the same region
where amplify cloudformation template was deployed. You can change the region
name from the top of aws console.
8. After you enter all the values on cloudformation stack, scroll down and acknowledge
both the check boxes.
10. After create complete, navigate to “VodAwsStack”, then navigate to outputs tab and
copy the following values in a notepad.
a. oVODInputS3
b. oVODOutputS3
c. oVODOutputUrl
11. Now go back to your Cloud9 IDE console. Navigate to the “src” directory
a. cd /home/ec2-user/environment/VodAws/src/
12. Create a file named “aws-video-exports.js” and paste the below code
const awsvideoconfig = {
"awsInputVideo": "Your Input S3 Bucket Name",
"awsOutputVideo": "Your Cloudfront Url"
};
13. Enter S3 bucket name obtained from above step as “oVODInputS3” value and
Cloudfont url as “oVODOutputUrl” value
? Select the environment setup: PROD (S3 with CloudFront using HTTPS)
? Accept the propose hosting bucket name that looks like odws-20200518075723-
hostingbucket
Static webhosting is disabled for the hosting bucket when CloudFront Distribution is
enabled.
1. Now we need an Admin user to test out the authentication functionality, let's create an
admin user through the Cognito console.
4. Select the userpool labeled "VodAws" or your project name + a random string.
6. Select the blue "create user" button and enter the user creation form. You will need to
enter a phone number that includes country code, for example +15558888888
7. Fill out the form to create a user. Now we will have to add admin privileges in order
to enable this user to publish videos through the app.
9. Select the blue "Add to Group" button, and select the admin group.
10. Go back to the react application (localhost:3000/Admin) and log in and create a new
password.
12. Create a user account using the app sign-up page instead of the Cognito console. You
may have to sign out if you're still logged in as the admin user.
13. For user-acccount the url will be > “Cloudfronturl.net”
14. Refresh the tab that the application is running in to see the login page. (react's local
dev server may do this for you)
15. Create a new user. This user will not be an admin and thus won't have rights to
publish content to VodAws. Make sure to provide a valid email to activate your
account. The code may take a minute or two to arrive in your inbox.
16. Login to the react application from the newly created user and you will be able to
watch the video uploaded by admin.
Troubleshoot:
To forward the headers from your CloudFront distribution, follow these steps:
2. Choose the Behaviors tab.
5. Under Whitelist Headers, choose headers from the menu on the left, and then
choose Add.
7. Choose Yes, Edit.
Note that if the hosting S3 bucket is newly created in regions other than us-east-1, you might
get the HTTP 307 Temporary Redirect error in the beginning when you access your
published application through CloudFront. This is because CloudFront forwards requests to
the default S3 endpoint (s3.amazonaws.com), which is in the us-east-1 region, and it can take
up to 24 hours for the new hosting bucket name to propagate globally.