AWS Cloud9 and S3 - rajeshkumarplv/aws-ccp-notes GitHub Wiki
A cloud IDE for writing, running, and debugging code
AWS Cloud9 is a cloud-based integrated development environment (IDE) that lets you write, run, and debug your code with just a browser. It includes a code editor, debugger, and terminal.
-
Cloud9 comes prepackaged with essential tools for popular programming languages, including JavaScript, Python, PHP, and more, so you don’t need to install files or configure your development machine to start new projects.
-
Since your Cloud9 IDE is cloud-based, you can work on your projects from your office, home, or anywhere using an internet-connected machine.
-
Cloud9 also provides a seamless experience for developing serverless applications enabling you to easily define resources, debug, and switch between local and remote execution of serverless applications. With Cloud9, you can quickly share your development environment with your team, enabling you to pair program and track each other's inputs in real time.
-
An AWS Cloud9 environment is a place where you store your project's files and where you run the tools to develop your applications.
Using the AWS Cloud9 IDE, you can:
-
Store your project's files locally on the instance or server.
-
Clone a remote code repository— such as a repo in AWS CodeCommit —into your environment.
-
Work with a combination of local and cloned files in the environment.
You can create and switch between multiple environments, with each environment set up for a specific development project. By storing the environment in the cloud, your projects no longer need to be tied to a single computer or server setup. This enables you to do things such as easily switch between computers and more quickly onboard developers to your team.
Create an S3 Bucket
ec2-user:~/environment/aws-modern-application-workshop (java) $ aws s3 mb s3://rajpillufirstawss3bucket make_bucket: rajpillufirstawss3bucket
You can verify that the bucket was created successfully using the aws s3 ls command.
ec2-user:~/environment/aws-modern-application-workshop (java) $ aws s3 ls s3://rajpillufirstawss3bucket
###Update the S3 Bucket Policy
To serve as a public website, we can create an S3 Bucket Policy that indicates objects stored within this new bucket are publicly accessible. S3 Bucket Policies are represented as JSON documents that authorizes or denies the invocation of S3 Actions (S3 API calls) to Principals (in our public example case, anyone).
bucket-policy.json
{ "Id": "MyPolicy", "Version": "2012-10-17", "Statement": [ { "Sid": "PublicReadForGetBucketObjects", "Effect": "Allow", "Principal": "", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::rajpillufirstawss3bucket/" } ] }
How to delete a bucket policy?
aws s3api delete -bucket-policy --bucket rajpillufirstawss3bucket
CLI command to add a public bucket policy to your website:
aws s3api put-bucket-policy --bucket rajpillufirstawss3bucket --policy file://~/environment/aws-modern-application-workshop/module-1/aws-cli/website-bucket-policy.json
Access the S3 object
curl -I "https://rajpillufirstawss3bucket.s3.amazonaws.com/index.html" HTTP/1.1 200 OK
Configure website Hosting
aws s3 website s3://rajpillufirstawss3bucket --index-document index.html
URL of the site: http://rajpillufirstawss3bucket.s3-website-us-east-1.amazonaws.com/
Hosting a static website using Amazon S3
To host a static website on Amazon S3, you configure an Amazon S3 bucket for website hosting and then upload your website content to the bucket. When you configure a bucket as a static website, you must enable website hosting, set permissions, and create and add an index document. Depending on your website requirements, you can also configure redirects, web traffic logging, and a custom error document.
After you configure your bucket as a static website, you can access the bucket through the AWS Region-specific Amazon S3 website endpoints for your bucket. Website endpoints are different from the endpoints where you send REST API requests. For more information, see Website endpoints. Amazon S3 doesn't support HTTPS access for website endpoints. If you want to use HTTPS, you can use CloudFront to serve a static website hosted on Amazon S3.