Course Content
Introduction to Cloud Computing
Introduction to Cloud Computing
Storing Code Fragments On AWS S3
We created some HTML code that lets us feed the turtle, and in this code, we used an image that we uploaded to AWS S3 in a public bucket. You might have noticed, though, that reading the code directly from there was quite inconvenient due to the large number of styles.
This leads us to the idea that we can also upload certain code snippets to AWS S3, just like we do with images. For example, in our case, it would be really convenient to upload CSS styles for our HTML pages or applications to AWS, helping us keep the code cleaner and more organized.
Let's take a look at the style file I want to upload to the storage:
index.css
To add a file with styles to AWS S3, we first need to create the file and upload it to our public bucket:
To apply these CSS styles in your HTML code, you just need to use a straightforward syntax:
In the case of linking to our styles, this line will look like this:
Let’s take a look at how much our code will be reduced after these changes and how it will look now:
index.html
If you click and follow this link, you'll see the contents of this file, specifically the styles I wrote earlier. This way, both we and the visitors to our website can view the styles stored on AWS and may want to borrow them from us.
It's also worth noting that we can upload JavaScript scripts to S3. While this is not the best practice because scripts often require editing and working with them, in our case, we are learning, so let’s go ahead and do it to further streamline our code!
Below is the script we'll be uploading to our public bucket:
script.js
Now, we need to upload the JavaScript script file to our public bucket:
Now, we need to use the following syntax to add the script to the code via the link:
After adding the script from AWS S3, our code for the turtle will look like this:
index.html
Thanks for your feedback!