Continuing from the previous part, in this part let’s add CloudFront services and Snapshot services to the AWS-TUI app. Amazon CloudFront is a highly-secure Content Delivery Network(CDN) that provides both network and application-level protection. It’s a network of edge locations that provides very high-speed data transmission.
Here, aws_run.py is the entry-point of this app.
$ python3 aws_run.py
CloudFront directory contains the file cloudfront_services.py file. This file provides us many options to work with CloudFront services. Let’s discuss some options:
- Create Distribution: This option provides us a way to create a CloudFront distribution using CLI. It takes a bucket name and default root object as a parameter to create a CloudFront distribution.
Initially, we have two distributions.
After executing Create Distribution on S3 bucket named cankush625 and selecting a default root object as AutoTweetLiker.png, the new distribution is created with an ID starting from E1TWAK…
But, to take real advantage of CloudFront, we have to make our S3 bucket private. So, that anyone without the URL provided by CloudFront can’t access the S3 bucket content.
Also, we have to do some extra settings as shown in the figure below to access the CloudFront content. Follow this path to get the following screen: Services -> Networking and Content Delivery -> CloudFront -> Select the Distribution -> Distribution Settings -> Origin and Origin Groups -> Select Origin -> Edit. (All of these settings can be done by using a single JSON file. We will discuss that later).
Now, once this distribution is deployed, we can the content of the S3 bucket securely by using the URL given by CloudFront.
Now, let’s access another object in the same bucket by specifying the path of the object to the URL provided by CloudFront.
- Update Root Object: By using this option we can update/change the default root object of our CloudFront distribution. As we already know that our default root object is AutoTweetLiker.png, let’s make the white_rose.jpg as out default root object.
- List Distributions: Returns the list of all of the distributions. This function can be used to find the Distribution ID majorly along with other information like status, domain name, origin, etc.
- Get Distributions: Gives information about distribution by accepting the Distribution ID as an input. Along with all of this information, it gives one most important detail which is the ETag. The ETag HTTP response header is an identifier for a specific version of a resource.
- Delete Distribution: Deleting a distribution. It takes Distribution ID and ETag header as an input to perform the deletion of the CloudFront distribution.
Updated EC2 services:
Snapshot is a very powerful concept provided by AWS. By using snapshots, we can do the incremental-backup. Also, snapshots are so much powerful that by using them we can create our own custom AMI(Amazon Machine Image). The services/ec2/ebs_services.py file provides the functions to work with snapshots. Let’s discuss some of the functionalities:
- Create Snapshot: Creating a snapshot from an EBS volume. This function takes Volume ID, description, tag key name, and the tag value as an input and creates a new snapshot.
Initially, I’ve only one snapshot named ankush.
Let's run the create snapshot option.
After running the create snapshot function, the new snapshot is get created with the name SnapCLI.
- Describe Snapshot: Getting the details of the snapshot. This function takes snapshot ID as input and shows all of the details of the snapshot.
- Copy Snapshot: Used to copy the Snapshot from one region to another region. In this way, we can share the whole EBS volume from one region to another region. This function accepts the destination region name, source region name, snapshot ID, and the description as an input.
In the beginning, I don’t have any snapshot in the N. California region.
Let’s run the Copy Snapshot function to copy the snapshot from the ap-south-1(Mumbai region) to the us-west-1(N. California region).
After running the Copy Snapshot function, the snapshot from the ap-south-1 is get copied to the us-west-1 region.
- Delete Snapshot: Deleting the snapshot. This function takes the snapshot ID as an input.
Deleting the snapshot from the ap-south-1(my default region).
Here is the link for the source code of this app: https://github.com/cankush625/AWS-TUI
Until now, Part-3 of the upcoming many parts of the AWS-TUI app is completed. As I’m currently learning and implementing regularly these concepts in this app, this app will continue to upgrade day by day.