Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

1

Day 10: Agenda


AWS - Cloud Front, SQS & SNS
services

What is a AWS Cloud Front?


Why do we need Cloud Front?
How Cloud Front works?
SQS - What, Why and How it works?
SNS - What, Why and How it works?
2

What is a Cloud Front?


CloudFront is a content delivery network (CDN) provided by Amazon Web Services (AWS).

It is designed to deliver static and dynamic web content, including images, videos, applications, and APIs, to users with low latency
and high data transfer speeds.

CloudFront operates by caching content in edge locations, which are distributed globally, bringing the content closer to end-users and
reducing the time it takes for the content to reach them.

When a user requests content that is served through CloudFront, the request is routed to the nearest edge location,
which then delivers the content from its cache if it's available.

If the content is not cached or has expired, CloudFront retrieves it from the origin server, such as an S3 bucket, an EC2 instance,
or a load balancer, and caches it at the edge location for subsequent requests.

CloudFront offers several benefits, including improved website performance, reduced latency, and increased scalability.

It can handle high volumes of traffic and effectively distribute the load across multiple edge locations.

CloudFront also integrates with other AWS services, such as Amazon S3, EC2, and Elastic Load Balancing, providing seamless integration
and enhanced capabilities for content delivery.

Furthermore, CloudFront supports various content delivery features, such as dynamic content generation, SSL/TLS encryption,
access control, and real-time logging and monitoring. It allows users to customize caching behavior, set up content delivery rules,

Why Cloud Front?


There are several reasons why organizations choose to use CloudFront as their content delivery network (CDN). Here are some of the key bene ts and reasons for using CloudFront:

1.Improved Performance: CloudFront helps improve the performance of websites and applications by caching content at edge locations distributed globally. This reduces the
latency and improves the response time for end-users, as the content is served from a location closer to them. Faster content delivery results in a better user experience and
increased customer satisfaction.
2.Scalability: CloudFront is highly scalable and can handle high volumes of traf c. It automatically scales to accommodate increased demand and effectively distributes the load
across multiple edge locations. This scalability is particularly useful for websites or applications that experience sudden traf c spikes or need to serve content to a large user base.
3.Global Reach: With CloudFront, you can deliver content to users around the world. It has a large network of edge locations strategically placed in different geographic locations,
ensuring that content is delivered with minimal latency regardless of the user's location. This global reach is crucial for organizations targeting a global audience or operating in
multiple regions.
4.Integration with AWS Services: CloudFront seamlessly integrates with other AWS services, such as Amazon S3, EC2, and Elastic Load Balancing. This integration allows you to
easily distribute and deliver content stored in these services through CloudFront. It also enables you to take advantage of additional AWS features and services to enhance your
content delivery.
5.Security and Protection: CloudFront offers various security features to protect your content and applications. It supports SSL/TLS encryption, allowing you to deliver content
securely over HTTPS. CloudFront can also integrate with AWS Web Application Firewall (WAF) to protect against common web exploits and provide additional security measures.
6.Cost-Effectiveness: CloudFront offers a pay-as-you-go pricing model, which means you only pay for the actual data transfer and requests made through the CDN. This makes it
cost-effective, especially for organizations with varying traf c patterns or seasonal spikes in demand. Additionally, CloudFront's caching mechanism reduces the load on your origin
server, potentially lowering your infrastructure costs.
7.Customization and Flexibility: CloudFront provides various customization options to tailor the content delivery behavior according to your speci c requirements. You can
con gure caching rules, set up content delivery policies, and optimize content for different devices and network conditions. This exibility allows you to optimize performance and
user experience based on your unique needs.
These are some of the reasons why organizations choose CloudFront as their CDN solution. It offers improved performance, scalability, global reach, integration with AWS services,
security features, cost-effectiveness, and customization options, making it a popular choice for content delivery.

4
fi

fi
fi
fi
fl
fi
fi
How Cloud Front works?
CloudFront operates based on a distributed architecture that involves edge locations, origin servers, and caching. Here's how CloudFront works:

1.Content Distribution: When a user requests content served through CloudFront, the request is rst routed to the nearest edge location. CloudFront has a global network of edge locations
strategically distributed worldwide, closer to end-users. This routing is performed based on various factors like the user's geographic location, latency, and availability of the content in the cache.
2.Caching: At the edge location, CloudFront checks if the requested content is already cached. If the content is present in the cache and hasn't expired, the edge location serves it directly to the
user, resulting in faster response times and reduced load on the origin server. This caching behavior can be customized through various cache control mechanisms, such as setting time-to-live
(TTL) values and cache invalidation.
3.Origin Server Interaction: If the requested content is not present in the cache or has expired, the edge location acts as a proxy and forwards the request to the origin server. The origin server
can be an Amazon S3 bucket, an EC2 instance, a load balancer, or any other publicly accessible server. CloudFront retrieves the content from the origin server and caches it at the edge
location for subsequent requests.
4.Dynamic Content Generation: CloudFront also supports dynamic content generation. When a request for dynamic content is received at an edge location, CloudFront can be con gured to
route the request to an appropriate server or service that generates the content dynamically. This enables ef cient delivery of personalized or real-time generated content while bene ting from
the global network and caching capabilities of CloudFront.
5.Global Updates: When content is updated or changed at the origin server, CloudFront provides mechanisms for ensuring the updated content is propagated to the edge locations. This includes
cache invalidation, which allows you to explicitly remove speci c content from the edge locations, and cache control headers that control how CloudFront caches and serves the content.
CloudFront also supports content versioning to ensure that updated versions of content are served to users.
6.Integration with AWS Services: CloudFront seamlessly integrates with other AWS services. For example, you can con gure CloudFront to retrieve content from an Amazon S3 bucket,
distribute traf c to EC2 instances through Elastic Load Balancing, or authenticate and authorize access to content using AWS Identity and Access Management (IAM) or Amazon Cognito. This
integration enhances the capabilities and exibility of content delivery through CloudFront.
7.Logging and Monitoring: CloudFront provides logging and monitoring capabilities to track the performance and usage of your content delivery. You can enable access logs to record detailed
information about each request, including the source IP, timestamp, response codes, and more. CloudFront also integrates with AWS monitoring services like Amazon CloudWatch, allowing you
to monitor key metrics and set up alarms to ensure optimal performance and availability.
By utilizing this architecture and leveraging its caching and distribution capabilities, CloudFront helps deliver content ef ciently with low latency, high availability, and global reach, improving the
user experience and performance of websites and applications.
5
fi
fl

fi
fi
fi
fi
fi
fi
fi
How Cloud Front works in AWS:-

6
How Cloud Front works in AWS:-

7
How Cloud Front works in AWS:-

8
How to use Cloud Front to serve Private S3 buckets to a website:-

9
How to use Cloud Front to serve Private S3 buckets to a website:-
CloudFront Lab steps:-
create s3 bucket - enable public all access - add index.html, error.html -> static web hosting enable -> give the index.html and error.html
try access the s3 static web hosting url - 403 forbidden -> because the objects are not having the public access
so, give the public access to index.html, error.html les and try access the s3 static web hosting url
give some random letters in the end of the s3 static web hosting url -> you should get the custom error message de ned in the error.html page

Now go to Cloud front -> Securely deliver content with low latency and high transfer speeds
Enable accelerated, reliable and secure content delivery for Amazon S3 buckets, Application Load Balancers, Amazon API Gateway APIs, and more in 5 minutes or less.

Create a CF Distribution --> origin as s3 bucket which we created above -> origin domain = s3 web hosting url
Keep the rest all defaults and create the distribution

Now open the distribution-> copy the distribution domain name and hit in the browser -> you will see the response from the s3 bucket as like same here
give some random letters in the end of the distribution domain name url -> you should get the custom error message de ned in the error.html page

Now try to see the invalidation --?


Make the changes to the index.html le and upload in the same location and make the index.html le as public again
--> try hit the s3 static web hosting url -> you see the new changes
--> try hit the distribution domain name url -> you won't see the new changes

So, we need to make the CF to get the latest updates from the S3 with the help of invalidations --> create invalidation -> give it as /index.html

Also, try give the S3 URL and distribution domain name url to the students to access from India
Now, create the restrictions from India and verify the behavior.
10
fi
fi
fi
fi
fi
How SQS works in AWS:-
SQS stands for Simple Queue Service, which is a fully managed message queuing service provided by Amazon Web Services (AWS). It offers a reliable and scalable platform for decoupling
components and systems within distributed applications.

SQS enables applications to send, store, and receive messages between different software components, allowing them to operate asynchronously. It follows a distributed architecture, where
messages are stored in a queue and can be processed by consumers at their own pace. This asynchronous messaging pattern helps in building loosely coupled and highly scalable systems.

Key features and characteristics of SQS include:

1.Messaging Model: SQS follows a messaging model where senders (producers) place messages into a queue, and receivers (consumers) retrieve and process messages from the queue. This
decoupling allows different components or services to work independently without having to be aware of each other.
2.Fully Managed Service: AWS manages the underlying infrastructure and resources required to operate SQS, including hardware provisioning, scaling, and maintenance. This relieves users
from the operational overhead and allows them to focus on building their applications.
3.Scalability and Durability: SQS is designed to be highly scalable and durable. It can handle a large volume of messages and automatically scales to accommodate increased throughput.
Messages in SQS are replicated across multiple availability zones within a region, providing high availability and durability.
4.Message Visibility and Retention: When a message is retrieved by a consumer from the queue, it becomes temporarily invisible to other consumers. This visibility timeout ensures that only
one consumer processes the message at a time. If the consumer fails to process the message within the timeout period, it becomes visible again and can be picked up by another consumer.
Messages in the queue can be retained for a con gurable period, allowing delayed processing or reprocessing of failed messages.
5.Ordering and Priority: SQS provides support for message ordering within a single queue. Messages sent in the same order are processed in the same order. Additionally, SQS allows
assigning priorities to messages, enabling consumers to process high-priority messages rst.
6.Message Delivery Semantics: SQS guarantees at-least-once delivery of messages. It means that a message sent to the queue will be delivered to a consumer at least once, but it might be
delivered multiple times in case of failures or retries. To handle duplicate messages, consumers should implement deduplication logic in their application.
7.Integration with AWS Services: SQS seamlessly integrates with other AWS services. For example, it can be used in combination with AWS Lambda, Amazon EC2, and Amazon S3 to build
serverless architectures, process events, or decouple different components of a system.
SQS provides a reliable and scalable way to decouple components, distribute workloads, and build fault-tolerant and highly available applications. It is suitable for various use cases such as task
processing, event-driven architectures, and building resilient and loosely coupled systems.

11
fi
fi
Why SQS:-
Queues can be used to handle malfunctions in the scalability of services. when a service depends
on another service that can not scale to the same level. Having a queue between A and B is useful
in such situations because the queue can handle peak demand from A, and send messages at a
slower rate with which B can cope. Where A will send a message directly to B this may cause an
issue if B System gets failure, corrupt, or lost data during loading data to solve this we are gone
using SQS Service where this acts as Intermediator which stores data and sends to B so even B
gets failure until that system set up this will be stored in SQS than sent to B.

SQS automatically deletes messages that have been in a queue for more than the maximum
message retention period. The default message retention period is 4 days. However, you can set
the message retention period to a value from 60 seconds to 1,209,600 seconds (14 days) using
the SetQueueAttributes action.
12
How SQS works in AWS:-

13
How SQS works in AWS:-

14
How SQS works in AWS:-

15
How SQS works in AWS:-

16
How SQS works in AWS:-

17
How SQS works in AWS:-

18
How SQS works in AWS:-

19
How SQS works in AWS:-
$ docker run --env AWS_ACCESS_KEY_ID=AKIAVDI34NU5SEWWX2O2 --env AWS_SECRET_ACCESS_KEY=scfVnkj8AonqrLhlosN/U9hBXiluN6u7DOCHxHDy -p 8080:8080 spring-boot-sqs-example

AWS Root user Access Key & secret key:

AKIAVDI34NU5SEWWX2O2

scfVnkj8AonqrLhlosN/U9hBXiluN6u7DOCHxHDy

"reference" : "T000000012345",

"userId" :"TEST_USERID",

"coupon": "FIRSTBUY15OFF",

"products" :

"productId": "PRODUCT1",

"productName": "Baggy Jeans",

"price": 26.78,

"code": "T0012"

} 20
What is SNS in AWS:-

21
What is SNS in AWS:-

22
What is SNS in AWS:-

23
24

You might also like