Takeaway
Takeaway - Security
-
Data Encryption / Decryption
- Usually refers to
data at rest
encryption / decryption, in which case users need to explicitly specify the encryption key (symmetric). - Since the encryption key needs to be specified explicitly,
data at rest
encryption isnot enabled by default
. Data in transit
encryption isenabled by default
and does not need user intervention, but users must adoptTLS
supported endpoints for encryption to work.
- Usually refers to
AWS Architecture
AWS Architecture Center (opens in a new tab)
Migrate & Modernize
Migrate & Modernize (opens in a new tab)
-
- Relocate (Containers / VMware Cloud on AWS)
- Rehost / lift-and-shift
- Replatform / lift-and-reshape
- Repurchase / replace
- Refactor / rewrite
- Retain / move
- Retire / decommission
AWS Whitepapers
AWS Well-Architected Framework
AWS Well-Architected Framework (opens in a new tab)
Operational excellence
Security
Reliability
Disaster Recovery (DR)
Disaster Recovery (DR) (opens in a new tab)
-
Recovery Time Objective
(RTO
) is the maximum acceptable delay between the interruption of service and restoration of service. This determines what is considered an acceptable time window when service is unavailable. -
Recovery Point Objective
(RPO
) is the maximum acceptable amount of time since the last data recovery point. This determines what is considered an acceptable loss of data between the last recovery point and the interruption of service. -
DR strategies (opens in a new tab)
-
Backup & Restore
RPO
/RTO
: Hours- Lower priority use cases
- Provision all AWS resources after event
- Restore backups after event
- Cost
$
-
Pilot Light
RPO
/RTO
: 10s of minutes- Data live
- Services idle
- Provision some AWS resources and scale after event
- Cost
$$
-
Warm standby
RPO
/RTO
: Minutes- Always running, but smaller
- Business critical
- Scale AWS resources after event
- Cost
$$$
-
Multi-site
RPO
/RTO
: Real-time- Zero downtime
- Near zero data loss
- Mission Critical Services
- Cost
$$$$
-
-
Resources
Performance efficiency
Cost optimization
Sustainability
CLI
- AWS Docs - AWS CLI - User Guide for Version 2 (opens in a new tab)
- AWS CLI v2 Command Reference (opens in a new tab)
- Configuration and credential file settings in the AWS CLI (opens in a new tab)
CLI - Pagination
Pagination (opens in a new tab)
-
By default, the
AWS CLI
uses apage size
of1000
and retrievesall available items
. -
If
all available items
are more thanpage size
, multipleAPI
calls are made untilall available items
are returned. -
Parameters
-
--no-paginate
Return only the first page of results, therefore single
API
call -
--page-size
Specify the number of items in a single page (by default
1000
) -
--max-items
Specify the total number of items returned (by default
all available items
) -
--starting-token
When
--max-items
specifies a number smaller thanall available items
, the output will include aNextToken
retrieving the remaining items.
-
CLI - Tagging
Find resources by specified tags in the specific Region
aws resourcegroupstaggingapi get-resources \
--tag-filters Key=Environment,Values=Production \
--tags-per-page 100
CLI - Filter
-
Server-side filtering
-
For filter name, refer to API documentation of the resource action.
CLI - Cheatsheet
CLI - CloudWatch - Get Log Groups
aws logs describe-log-groups
CLI - CloudWatch - Get Log Streams
aws logs describe-log-streams --log-group-name <log-group-name>
CLI - CloudWatch - Get Log Events
-
aws logs get-log-events --log-group-name <log-group-name> --log-stream-name <log-stream-name> --limit 100
-
aws logs get-log-events --log-group-name <log-group-name> --log-stream-name <log-stream-name> --start-time <start-time> --end-time <end-time>
CLI - CloudWatch - Get paginated all log events of a log group in text output
-
aws logs filter-log-events --log-group-name <log-group-name> --output text
Suitable for general browsing
CLI - CloudWatch - Search keyword in log events of a log group
aws logs filter-log-events --log-group-name <log-group-name> --limit 100 --filter-pattern %Keyword%
CLI - S3 - Listing all user owned buckets
aws s3 ls
Cost Management
AWS Docs - Cost Management (opens in a new tab)
Savings Plans
AWS Docs - Savings Plans (opens in a new tab)
-
In addition to
EC2
, also applicable only toFargate
andLambda
-
Aims to simplify savings planning on
EC2
instances -
Types
-
Compute Savings Plans
-
Most flexible
- EC2
- ECS Fargate
- Lambda
-
Up to 66% off of On-Demand rates
-
-
EC2 Instance Savings Plans
-
Provide the lowest prices, offering savings up to 72% in exchange for commitment to usage of individual instance families in a
Region
(e.g. M5 usage in N. Virginia) -
Up to 72% off of On-Demand rates
-
-
SageMaker Savings Plans
- Up to 64% off of On-Demand rates
-
VPC
AWS Docs - VPC (opens in a new tab)
-
A
VPC
spans allAZ
s in theRegion
. -
CLI
-
aws ec2 create-default-vpc
create a default
VPC
-
aws ec2 create-default-subnet --availability-zone <AZ>
create a default
subnet
-
-
Recipes
-
Calculate subnet
CIDR
block based onVPC
CIDR
blockUse
ipcalc
-
-
References
VPC - Subnet
-
A
subnet
always belongs to oneVPC
once created. -
A
subnet
is associated with only oneAZ
. -
Subnet CIDR block
must be a subset of theVPC CIDR block
. -
172.16.0.0/21
means the first21
bits are used to identify network (subnet
), the rest of bits are used identify hosts. In this case,21
bits are used for network identification, while32 - 21 = 11
bits are used for host identification. Therefore, when assigning IP addresses, the first21
bits are fixed, while the rest bits will increment until all allocated. -
public
subnet
is asubnet
that's associated with aroute table
that has a route to aninternet gateway
. -
You can make a default
subnet
into a privatesubnet
by removing the route from the destination0.0.0.0/0
to theinternet gateway
. -
Resources
VPC - Route Table
- A
route table
always belongs to oneVPC
once created. - A
subnet
can only be associated with oneroute table
at a time, but you can associate multiplesubnet
s with the sameroute table
. - Each
subnet
in yourVPC
must be associated with aroute table
, which controls the routing for thesubnet
(subnet route table). - If not explicitly specified, the
subnet
is implicitly associated with themain route table
. - Your
VPC
has an implicitrouter table
, and you useroute tables
to control where network traffic is directed. - If your
route table
has multiple routes, we use the most specific route (longest prefix match) that matches the traffic to determine how to route the traffic.
VPC - Static IP Address
- When you stop an
EC2 instance
, itspublic IP
address is released. When you start it again, a newpublic IP
address is assigned.
VPC - Elastic IP Address
- If you require a public IP address to be persistently associated with the instance, allocate an
Elastic IP address
, essentially reserved public IP address. Elastic IP address
is free of charge when allocated to runningEC2
instances, while charge applies when they are reserved but not in use.
VPC - Network ACL
-
One
Network ACL
always belongs to oneVPC
once created. -
Operates at the
subnet
level, able to be associated with multiplesubnet
s within the sameVPC
, operating like filters, thereforestateless
. -
Black / white list
-
Return traffic must be explicitly allowed by rules
-
Rules evaluation order
- By
Rule number
in ascending order - First matched first served like a if/else block
- By
VPC - Security Group
- Operates at the
instance
level, therefore only in effect when associated withinstance(s)
, thereforestateful
. - By default, a
security group
includes anoutbound rule
that allows alloutbound
traffic. White list only
, you can specify allow rules, but not deny rules.- Return traffic is automatically allowed, regardless of
Inbound
orOutbound
Inbound
rules only specifysource IP
, whileOutbound
rules only specifydestination IP
.- All rules are evaluated before a decision is made.
At most 5 Security Group
can be associated with aninstance
, and union of all rules from the all associatedSecurity Group
would be applied to theinstance
.- When you specify a
security group
as the source for an inbound or outbound rule, traffic is allowed from the network interfaces that are associated with the sourcesecurity group
for the specified protocol and port. Incoming traffic is allowed based on the private IP addresses of the network interfaces that are associated with the sourcesecurity group
(and not thepublic IP
orElastic IP addresses
). Adding asecurity group
as a source does not add rules from the sourcesecurity group
. Default security group
cannot be deleted.By default
, asecurity group
includesan outbound rule that allows all outbound traffic
.
VPC - Security Group - CLI Cheatsheet
VPC - Security Group - Get all Security Group rules permitting inbound traffic on the given TCP port
aws_ec2_describe_security_groups_rules_ingress () {
local protocol=$1
local port=$2
local filters='!IsEgress && (IpProtocol == `'${protocol}'` || IpProtocol == `-1`) && (FromPort <= `'${port}'` && ToPort >= `'${port}'` || FromPort == `-1` && ToPort == `-1`)'
aws ec2 describe-security-group-rules \
--query "sort_by(SecurityGroupRules, &GroupId)[? $filters].{GroupID: GroupId, From: FromPort, To: ToPort, CIDR: CidrIpv4, RuleID: SecurityGroupRuleId}" \
--output table
}
aws_ec2_describe_security_groups_rules_ingress tcp 22
VPC - Security Group - Create a Security Group in the given VPC
aws ec2 create-security-group \
--group-name $group_name \
--description $description \
--vpc-id $vpc_id
VPC - Security Group - Add an inbound rule to the given Security Group
aws ec2 authorize-security-group-ingress \
--group-id $group_id \
--protocol $protocol \
--port $port \
--cidr $cidr
# e.g. allowing traffic from a given IP
# aws ec2 authorize-security-group-ingress \
# --group-id sg-1234567890abcdef0 \
# --protocol tcp \
# --port 22 \
# --cidr 10.64.1.121/32 // Only one host is allowed
VPC - ENI (Elastic network interface)
AWS Docs - ENI (Elastic network interface) (opens in a new tab)
- Once created,
ENI
s are specific to asubnet
, but anElastic IP
can be disassociated from anENI
and available again. ENI
can be detached from anEC2 instance
, and attached to another instance.- The
primary ENI
cannot be detached from anEC2 instance
.
VPC Connection Options
VPC - Internet Gateway
AWS Docs - Internet Gateway (opens in a new tab)
- Only one
Internet Gateway
can beattached
to oneVPC
at a time. - Instances must have
public IPs
. - Attaching an
Internet Gateway
to aVPC
allowsinstances
withpublic IPs
to access the internet.
VPC - Egress-only Internet Gateway
AWS Docs - Egress-only Internet Gateway (opens in a new tab)
-
IPv6
- An
egress-only internet gateway
is for use withIPv6
traffic only. IPv6
addresses are globally unique, and are therefore public by default.
- An
-
IPv4
- To enable
outbound-only
internet communication overIPv4
, use aNAT gateway
instead.
- To enable
VPC - NAT Gateway
NAT Gateway (opens in a new tab)
- Fully managed, highly available
EC2
instance NAT Gateway
allows privatesubnet
to access theinternet
,NAT Gateway
must have anEIP
.NAT Gateway
traffic must be routed toInternet Gateway
in theroute table
.- It only works one way. The
internet
cannot get through yourNAT
to your private resources unless you explicitly allow it. EIP
cannot be detached.- Bandwidth up to
45 Gbps
- Cannot be associated with a
Security Group
- Cannot function as a
Bastion
host
VPC - NAT Instance
- Self managed, but with more flexibility and customization
- An
EC2
instance configured to performNAT
EIP
can be detached.- Can be associated with a
Security Group
- Can function as a
Bastion
host
VPC - VPC endpoint
-
A
VPC endpoint
enables you to privately connect yourVPC
to supportedAWS
services andVPC endpoint
services powered byAWS PrivateLink
(opens in a new tab) without requiring aninternet gateway
,NAT device
,VPN connection
, orAWS Direct Connect connection
. -
VPC endpoint
typesInterface endpoint
Gateway Load Balancer endpoint
Gateway endpoint
-
Key points
-
Pros
- Secure and private connection
- No internet needed
-
Cons
- Not all services are supported
- Not all
Regions
are supported - Cross region not supported
-
VPC - Interface endpoint
- An
interface endpoint
is anENI
with a private IP address from the IP address range of yoursubnet
that serves as an entry point for traffic destined to a supported service. interface endpoints
are powered byAWS PrivateLink
, which bills you for each hour that yourVPC endpoint
remains provisioned in eachAZ
, irrespective of the state of its association with the service.
VPC - Gateway endpoint
- A
gateway endpoint
is a gateway that you specify as a target for a route in yourroute table
for traffic destined to a supportedAWS
service. - Doesn't use
PrivateLink
, therefore no hourly charge. - Only work in the same
Region
- Only
S3
andDynamoDB
are supported Gateway endpoints
do not allow access from on-premises networks, frompeered VPCs
in otherRegions
, or through a transit gateway.
VPC peering
AWS Docs - VPC peering (opens in a new tab)
- A
VPC peering
connection is a networking connection between twoVPCs
that enables you to route traffic between them using privateIPv4
addresses orIPv6
addresses. Instances in eitherVPC
can communicate with each other as if they are within the same network. You can create aVPC
peering connection between your ownVPCs
, or with aVPC
in another AWS account. TheVPCs
can be in differentRegions
(also known as aninter-Region VPC peering connection
).
EC2
AWS Docs - EC2 (opens in a new tab)
-
Instance
-
Each
Linux instance
launches with adefault Linux system user account
. Log in asdefault user
to administrate theinstance
, whiledefault user
is not aroot user
, it has permissions to install additional software. -
To get password of
default administrator
on aWindows instance
, you have to decrypt it with theEC2 instance key pair private key
. -
EC2 metadata service
is only accessible from theinstance
for query ofmeta information
, such asIAM Role
name but notIAM policy
. -
User data
- Scripts entered as
user data
are executed as the root user. - By default,
user data
scripts and cloud-init directives run only during the boot cycle when you first launch an instance.
- Scripts entered as
-
AMI
isRegion
specific.AMI
can’t be changed for an existing instance.
-
Root volume
(opens in a new tab)- The
root volume
contains theimage
used to boot the instance. - Each instance has a single
root volume
. Instance store
backed orEBS
backed
- The
-
Use
Security Token Service (STS)
to decodeencoded authorization message
-
-
Instance
purchasing options-
On-Demand
-
Reserved Instance
(opens in a new tab)-
When you purchase a
Reserved Instance
, you determine the scope of theReserved Instance
to be eitherregional
orzonal
. -
By default, when you purchase a
Reserved Instance
, the purchase is made immediately. Alternatively, you can queue your purchases for a future date and time. You can queue purchases forregional Reserved Instances
, but notzonal Reserved Instances
orReserved Instances
from other sellers. -
Provide a capacity reservation when used in a specific
AZ
, applicable toEC2
,RDS
,Redshift
andElastiCache
Standard
- Modifiable
- Cannot exchange a
Standard Reserved Instance
- Can be sold in the
Reserved Instance Marketplace
Convertible
- Modifiable
- Can exchange a
Convertible Reserved Instance
- Cannot be sold in the
Reserved Instance Marketplace
-
Scope
Regional
Zonal
AZ flexibility Region AZ Capacity reservation ❌ ✅ Instance size flexibility Same instance family ❌ Queuing a purchase ✅ ❌ -
Reserved Instance Marketplace (opens in a new tab)
- Supports the sale of third-party and AWS customers' unused
Standard Reserved Instances
- Supports the sale of third-party and AWS customers' unused
-
-
Scheduled Instance
Capacity reservations that recur on a daily, weekly, or monthly basis, with a specified start time and duration, for a one-year term
-
Spot Instance
-
Unused
EC2
capacity in theAWS
cloud for stateless, fault-tolerant workload -
Spot Instance interruption
(opens in a new tab)Spot Instance interruption is when
EC2
reclaims aSpot Instance
. -
Spot Fleet
(opens in a new tab)A
Spot Fleet
is a collection, or fleet, ofSpot Instances
, and optionallyOn-Demand Instances
to meet the target capacity that you specified in theSpot Fleet
request.
-
-
Dedicated Host
&Dedicated Instance
(opens in a new tab)Physical server fully dedicated for your use
-
-
Placement groups (opens in a new tab)
-
Cluster
Packs instances close together inside an
Availability Zone
. This strategy enables workloads to achieve the low-latency network performance necessary for tightly-coupled node-to-node communication that is typical of high-performance computing (HPC) applications. -
Partition
Spreads your instances across logical partitions such that groups of instances in one partition do not share the underlying hardware with groups of instances in different partitions. This strategy is typically used by large distributed and replicated workloads, such as Hadoop, Cassandra, and Kafka.
-
Spread
Strictly places a small group of instances across distinct underlying hardware to reduce correlated failures.
-
-
Key pair
- For
SSH
intoEC2
instances
- For
-
Troubleshoot
-
Error connecting to your instance:
Connection timed out
Verify there is a
Security Group
inbound rule
that allows traffic from your computer to a particular port (such as 22 for SSH).
-
-
Performance
-
Resources
EC2 - Cheatsheet
Use metadata service to get instance metadata within the instance
-
List all categories of metadata
curl http://169.254.169.254/latest/meta-data
-
Resources
Get instances by keyword in name
-
aws ec2 describe-instances --filters "Name=tag:Name,Values=*<keyword>*"
Server filter with
AWS CLI v2
-
aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.Tags[].Key == "Name" and (.Tags[].Value | contains("<keyword>")))'
Client filter with
jq
Get instances by state
aws ec2 describe-instances --filters "Name=instance-state-name,Values=running|stopped"
Get instance types and specification
aws ec2 describe-instance-types
Get public key of SSH key pair
aws ec2 describe-key-pairs --key-names <key-pair-name> --include-public-key
Create/Update a tag of an instance
aws ec2 create-tags --resources <instance-id> --tags 'Key=<key>,Value=<value>'
List all tags of an instance
aws ec2 describe-tags --filters "Name=resource-id,Values=<instance-id>"
ELB (Elastic Load Balancing)
-
To distribute traffic between the instances (often in a
Auto Scaling group
) -
ELB
can be enabled within a singleAZ
or across multipleAZ
to maintain consistent application performance. -
Sticky Session (opens in a new tab)
AKA Session affinity, enabling the load balancer to bind a user's session to a specific
instance
. This ensures that all requests from the user during the session are sent to the sameinstance
, so user won't need to keep authenticating themselves. -
Load balancers
-
Application Load Balancer
-
Operate at
OSI Layer 7
-
Supports
WebSocket
andHTTP/2
-
Register targets in
target groups
and route traffic totarget groups
. -
Cross-zone load balancing
is always enabled. -
Access logs
capture detailed information about requests sent to theALB
. -
ALB
exposes a staticDNS
for access. -
Listeners
-
A
listener
is a process that checks for connection requests, using theprotocol
andport
that you configure. Therules
that you define for alistener
determine how theload balancer
routes requests to its registered targets. -
Listener rule condition types (opens in a new tab)
- host-header
- http-header
- http-request-method
- path-pattern
- query-string
- source-ip
-
Authenticate users (opens in a new tab)
- You can configure an
ALB
to securely authenticate users as they access your applications. This enables you to offload the work of authenticating users to your load balancer so that your applications can focus on their business logic.
- You can configure an
-
-
-
Network Load Balancer
- Operate at
OSI Layer 4
- Exposes a public static IP for access.
Cross-zone load balancing
is by default disabled.- Target type
EC2 Instances
IP addresses
- Operate at
-
Classic Load Balancer
- Only for
EC2 Instances
CLB
exposes a staticDNS
for access.- A
CLB
withHTTP
orHTTPS
listeners might route more traffic to higher-capacity instance types.
- Only for
-
-
Target group
-
Target type
-
One to many
EC2 Instances
- Supports load balancing to
EC2
instances within a specificVPC
. - Facilitates the use of
EC2 Auto Scaling
to manage and scale yourEC2
capacity.
- Supports load balancing to
-
One to many
IP addresses
- Supports load balancing to
VPC
and on-premises resources. - Facilitates routing to multiple
IP addresses
andnetwork interfaces
on the same instance. - Offers flexibility with microservice based architectures, simplifying inter-application communication.
- Supports
IPv6
targets, enabling end-to-endIPv6
communication, andIPv4-to-IPv6
NAT.
- Supports load balancing to
-
Single
Lambda
function- Facilitates routing to a single
Lambda
function. - Accessible to
ALB
only.
- Facilitates routing to a single
-
Application Load Balancer
- Offers the flexibility for a
NLB
to accept and routeTCP
requests within a specificVPC
. - Facilitates using static
IP
addresses andPrivateLink
with anALB
.
- Offers the flexibility for a
-
-
Protocol
- HTTP/1.1
- HTTP/2
- gRPC
-
-
Health Check
ELB - Cheatsheet
Describe all load balancers
aws elbv2 describe-load-balancers \
--query 'sort_by(LoadBalancers,&LoadBalancerName)[].{LoadBalancer:LoadBalancerName,Type:Type,DNS:DNSName}' \
--output table
Describe all listeners and their target group of the given load balancer
aws elbv2 describe-listeners \
--load-balancer-arn <load-balancer-arn> \
--query 'sort_by(Listeners,&ListenerArn)[].{Protocol:Protocol,Port:Port,TargetGroup:DefaultActions[0].TargetGroupArn}' \
--output table
Describe the given target groups
aws elbv2 describe-target-groups \
--filter Name=target-group-name,Values=<target-group-name> \
--query 'sort_by(TargetGroups,&TargetGroupName)[].{TargetGroup:TargetGroupName,Protocol:Protocol,Port:Port,VPC:VpcId}' \
--output table
Associate a Security Group with the given Load Balancer
aws elbv2 set-security-groups \
--load-balancer-arn $load_balancer_arn \
--security-groups $security_group_id
Show health state of all target groups
#!/bin/bash
# Get a list of all target groups
target_group_arns=($(aws elbv2 describe-target-groups --query "TargetGroups[].TargetGroupArn" --output text))
# Loop through the target groups and check if there are running instances
for arn in "${target_group_arns[@]}"; do
echo "Checking target group: $arn"
aws elbv2 describe-target-health \
--target-group-arn "$arn" \
--query 'TargetHealthDescriptions[].{"Target ID":Target.Id, Port:Target.Port, State:TargetHealth.State} | sort_by(@, &State)' \
--output table
done
EC2 - Auto Scaling
AWS Docs - Auto Scaling (opens in a new tab)
Auto Scaling group
can span across multipleAZs
within aRegion
, but not across multipleRegions
.Auto Scaling
works with all 3 load balancers.CloudWatch Alarms
can be used to triggerAuto Scaling
actions.
EC2 - Launch Template
AWS Docs - Launch Template (opens in a new tab)
-
Improvements over
Launch Configuration
-
Supports versioning, while
Launch Configuration
is immutable -
Supports multiple instance types and purchase options
-
More
EC2
options- Systems Manager parameters (AMI ID)
- The current generation of EBS Provisioned IOPS volumes (io2)
- EBS volume tagging
- T2 Unlimited instances
- Elastic Inference
- Dedicated Hosts
-
EC2 - ASG Capacity limits
ASG Capacity limits (opens in a new tab)
- After you have created your
Auto Scaling group
, theAuto Scaling group
starts by launching enoughEC2
instances to meet itsminimum capacity
(or itsdesired capacity
, if specified). - The
minimum
andmaximum capacity
are required to create anAuto Scaling group
. Desired capacity
(either by manual scaling or automatic scaling) must fall between theminimum
andmaximum capacity
.
EC2 - Scaling policy
AWS Docs - Scaling policy (opens in a new tab)
-
A
scaling policy
instructsAuto Scaling
to track a specificCloudWatch metric
, and it defines what action to take when the associatedCloudWatch alarm
is inALARM
. The metrics that are used to trigger an alarm are an aggregation of metrics coming from all of theinstances
in theAuto Scaling group
. -
Target tracking scaling
- The
scaling policy
adds or removes capacity as required to keep themetric
at, or close to, the specifiedtarget value
. - Triggered by an automatically created and managed
CloudWatch Alarm
byEC2 Auto Scaling
, which users shouldn't modify. - You don't need to specify scaling action.
- eg: Configure a
target tracking scaling
policy to keep the average aggregateCPU utilization
of yourAuto Scaling group
at40 percent
.
- The
-
Step scaling
- Triggered by a specified existing
CloudWatch Alarm
Scaling action
(add, remove, set) is based on multiple step adjustments
- Triggered by a specified existing
-
Simple scaling
- Triggered by a specified existing
CloudWatch Alarm
Scaling action
(add, remove, set) is based on a single scaling adjustment
- Triggered by a specified existing
-
Scaling cooldown (opens in a new tab)
A
scaling cooldown
helps you prevent yourAuto Scaling group
from launching or terminating additional instances before the effects of previous activities are visible.
EC2 - Scheduled Actions
Scheduled actions (opens in a new tab)
- Set up your own scaling schedule according to predictable load changes
EC2 - Termination Policy
Termination Policy (opens in a new tab)
-
Default termination policy
- Determine whether any of the instances eligible for termination use the oldest launch template or launch configuration.
- After applying the preceding criteria, if there are multiple unprotected instances to terminate, determine which instances are closest to the next billing hour.
EC2 Monitoring
- Instances (opens in a new tab)
- By default,
basic monitoring
is enabled when you create alaunch template
or when you use theAWS Management Console
to create alaunch configuration
. - By default,
detailed monitoring
is enabled when you create alaunch configuration
using theAWS CLI
or anSDK
.
- By default,
- Health check (opens in a new tab)
Auto Scaling
can determine the health status of aninstance
using one or more of the following:EC2
Status ChecksELB
Health Checks- Custom Health Checks
- The default health checks for an
Auto Scaling
group areEC2
status checks only.
EBS (Elastic Block Store)
-
Can only be attached to another
instance
within the sameAZ
-
Backup and restore
snapshot
can be used to share data withinstances
in anotherAZ
. -
Usually one volume can only be attached to one
instance
at a time (Multi-Attach
is not common) -
You can use block-level storage only in combination with an
EC2 instance
where theOS
is running -
After you attach an
EBS
volume to yourinstance
, it is exposed as a block device. You must create a file system if there isn't one and then mount it before you can use it.- New
volumes
are raw block devices without afile system
. Volumes
that were created fromsnapshots
likely have afile system
on them already.
- New
-
Amazon Data Lifecycle Manager
- Automate the creation, retention, and deletion of
EBS snapshots
andEBS-backed AMIs
- Automate the creation, retention, and deletion of
-
Snapshot
-
Incremental, tracking changes only
-
A volume becomes available right when the restore operation begins, even though the actual data had not yet been fully copied to the disk
-
Backup occur asynchronously; the point-in-time
snapshot
is created immediately, but the status of thesnapshot
is pending until thesnapshot
is complete -
Stored in
S3
-
Be aware of the performance penalty when initializing
volumes
fromsnapshots
-
Fast Snapshot Restore (opens in a new tab)
enables you to create a volume from a
snapshot
that is fully initialized at creation. This eliminates the latency of I/O operations on a block when it is accessed for the first time.
-
-
Volume types (opens in a new tab)
-
General Purpose SSD (opens in a new tab) (
gp2
,gp3
)gp2
volumes can support a sustained load of up to3000
IOPS for up to 30 minutes at a time.- IOPS/Volume
< 34 GiB
:100
IOPS>= 34 GiB & <= 5333 GiB
: incremental3
IOPS / GiB> 5333 GiB
:16,000
IOPS
-
Provisioned IOPS SSD (opens in a new tab) (
io1
,io2
,io2 Block Express
)-
Max IOPS/Volume:
64,000
-
The maximum ratio of
provisioned IOPS
torequested volume size
(inGiB
) is50:1
forio1
volumes, and500:1
forio2
volumes. -
io2 Block Express Volumes (opens in a new tab)
- Up to 4x higher throughput, IOPS, and capacity than
io2
volumes, and are designed to deliver sub-millisecond latency and 99.999% durability.
- Up to 4x higher throughput, IOPS, and capacity than
-
-
Throughput Optimized HDD (opens in a new tab) (
st1
)- It cannot be used as a bootable volume.
- Recommended for a large and linear workload such as
- Data warehouse
- Log processing
Amazon Elastic MapReduce (EMR)
, andETL
workloads
-
-
Performance Characteristics
Throughput = Size per IO Operation * IOPS
Size per IO Operation
- the amount of data written/read in a single IO request.
- data / request
EBS
merges smaller, sequential I/O operations that are32 KiB
or over to form a single I/O of256 KiB
before processing.EBS
splits I/O operations larger than the maximum256 KiB
into smaller operations.
IOPS
- the number of IO requests on a single block can be completed by the storage device in a second.
- requests / second
Throughput
- the amount of data transferred from/to a storage device in a second. Typically stated in
KB/MB/GB/s
- data / second
- the amount of data transferred from/to a storage device in a second. Typically stated in
-
Network bandwidth limits
EC2
instances accessEBS
volumes over network connections.EBS
volumes can be accessed using dedicated networks (available onEBS
-optimized instances) and shared networks (nonEBS
-optimized instances).
-
Encryption
- You encrypt
EBS
volumes by enabling encryption, either usingencryption by default
or by enabling encryption when you create a volume that you want to encrypt. EBS
encryption usesKMS
CMK
when creating encrypted volumes and snapshots.- Encryption operations occur on the servers that host
EC2
instances, ensuring the security of bothdata-at-rest
anddata-in-transit
between an instance and its attachedEBS
storage. Encryption by default
is aRegion
-specific setting. If you enable it for aRegion
, you cannot disable it for individual volumes or snapshots in thatRegion
.Volumes
- Can only be encrypted upon creation
- Encrypted
volumes
cannot be unencrypted.
Snapshots
Snapshots
created from an encryptedvolume
are always encrypted.- Encrypted
snapshots
cannot be unencrypted. - Unencrypted
snapshots
can only be encrypted when beingcopied
.
- Encrypted data include:
- Data at rest inside the
volume
- Data in transit between the
volume
and theinstance
- All
snapshots
created from thevolume
- All
volumes
created from thosesnapshots
- Data at rest inside the
- You encrypt
EFS (Elastic File System)
Region
-specific- Traditional filesystem hierarchy
- The main differences between
EBS
andEFS
is thatEBS
is only accessible from a singleEC2
instance in your particularRegion
, whileEFS
allows you to mount the file system across multipleRegions
andinstances
.
Elastic Beanstalk
-
PaaS
based onEC2
, usingCloudFormation
under the hood. -
Application
Application version lifecycle settings
(opens in a new tab)- If you don't delete versions that you no longer use, you will eventually reach the application version quota and be unable to create new versions of that application.
- You can avoid hitting the quota by applying an
application version lifecycle policy
to your applications.
- Removing
application
will also trigger removal of all associated resources such asenvironment
,EC2
Instance, etc.
-
Environment
- You can run either a
web server
environment or aworker
environment. - Use
Validate VPC Settings
button inEnvironment
tab to troubleshoot network. - If you associate an existing
RDS
instance to an existingEB
environment, theRDS
instance must be launched from asnapshot
. Environment
type can beLoad Balanced
orSingle Instance
.- When you terminate an
environment
, you can save its configuration to recreate it later. HTTPS
- The simplest way to use
HTTPS
with anElastic Beanstalk
environment is to assign a server certificate to your environment'sload balancer
.
- The simplest way to use
- You can run either a
-
Configuration (all under project root)
-
.ebextensions
(opens in a new tab) directory-
Configuration files are
YAML
orJSON
-formatted documents with a.config
file extension. -
Options can be specified as below, and is overridden as per precedence (opens in a new tab) rules
option_settings: - namespace: namespace option_name: option name value: option value - namespace: namespace option_name: option name value: option value
-
-
.elasticbeanstalk
directory-
Saved configuration
Saved configurations
areYAML
formatted templates that define an environment's platform version, tier, configuration option settings, and tags.Saved configurations
are located under.elasticbeanstalk > saved_configs
in project directory.
-
-
Config files in the project directory
-
env.yaml
You can include a
YAML
formatted environment manifest in the root of your application source bundle to configure the environment name, solution stack and environment links to use when creating your environment. -
cron.yaml
(Worker environment
)You can define periodic tasks in a file named
cron.yaml
in your source bundle to add jobs to yourworker environment
's queue automatically at a regular interval.
-
-
Elastic Beanstalk
supportsCloudFormation
functions (Ref
,Fn::GetAtt
,Fn::Join
), and oneElastic Beanstalk
-specific function,Fn::GetOptionSetting
.
-
-
-
Docker
- Single-container
- Multi-container
-
Custom platform
- A
custom platform
lets you develop an entire newplatform
from scratch, customizing the operating system, additional software, and scripts thatElastic Beanstalk
runs onplatform
instances. - To create a
custom platform
, you build anAMI
from one of the supported operating systems and add further customizations.
- A
-
-
EB CLI
-
Installation (opens in a new tab)
- Install
python3
- Install
pip3
- Install
awsebcli
- Install
-
Useful commands (opens in a new tab)
-
eb status
Gets environment information and status
-
eb printenv
Shows the environment variables
-
eb list
Lists all environments
-
eb setenv <env-variable-value-pairs>
Sets environment variables
eg:
eb setenv HeapSize=256m Site_Url=mysite.elasticbeanstalk.com
-
eb ssh
Opens the SSH client to connect to an instance
-
-
-
-
Creates an application version for the specified application (opens in a new tab)
aws elasticbeanstalk create-application-version \ --application-name MyApp \ --version-label v1 \ --description MyApp-v1 \ --source-bundle S3Bucket="<bucket-name>",S3Key="myApp.zip" \ --auto-create-application`
-
-
Deployment Strategies (opens in a new tab)
-
Update existing instances
-
All-at-once
Deploy the new version to all instances simultaneously.
-
Rolling
Updates are applied in a batch to running instances. The batch will be out of service while being updated. Once the batch is completed, the next batch will be started.
-
Rolling with an additional batch
The same as Rolling, except launching an additional batch of instances of the old version to rollback in case of failure. This option can maintain full capacity. When the deployment completes,
Elastic Beanstalk
terminates the additional batch of instances.
-
-
Deploying to new instances
-
Immutable
Instances of the new version are deployed as instances of the old version are terminated. There's no update to existing instances.
-
Traffic-splitting
(opens in a new tab)Elastic Beanstalk
launches a full set of new instances just like during animmutable
deployment. It then forwards a specified percentage of incoming client traffic to the new application version for a specified evaluation period. If the new instances stay healthy,Elastic Beanstalk
forwards all traffic to them and terminates the old ones.
-
-
Blue/Green
deployment (opens in a new tab)A new
environment
will be created for thenew version
(Green
) independent of thecurrent version
(Blue
). When theGreen
environment
is ready, you can swap theCNAMEs
of theenvironments
to redirect traffic to the newer runningenvironment
.Blue/green
deployments require that yourenvironment
runs independently of your production database, if your application uses one.
-
Summary
Method Impact of Failed Deployment Deploy Time Zero Downtime No DNS Change Rollback Process Code Deployed To All-at-once Downtime ⌚ ✅ Redeploy Existing instances Rolling Single batch out of service; any successful batches before failure running new application version ⌚⌚ ✅ ✅ Redeploy Existing instances Rolling with additional batch Minimal if first batch fails; otherwise, similar to Rolling ⌚⌚⌚ ✅ ✅ Redeploy Existing instances Blue/Green Minimal ⌚⌚⌚⌚ ✅ ❌ Swap URL New instances Immutable Minimal ⌚⌚⌚⌚ ✅ ✅ Redeploy New instances
-
-
Java
- Default port
5000
, to change that, updatePORT
environment variable. - From
Management Console
, the application to be uploaded must be an executableJAR
file containing all the compiled bytecode, packaged in aZIP
archive.
- Default port
CodeCommit
-
Region
specific -
No public access
-
Authentication
-
SSH
Dedicated
SSH key pair
of currentuser
forCodeCommit
only -
HTTPS
Dedicated
HTTPS Git credentials
of currentuser
forCodeCommit
only -
MFA
-
-
Authorization
-
IAM
You must have an
CodeCommit
managed policy attached to yourIAM
user, belong to aCodeStar
project team, or have the equivalent permissions.
-
-
Cross-Account access
to a different account- Create a
policy
for access to the repository - Attach this
policy
to arole
in the sameaccount
- Allow other
users
to assume thisrole
- Create a
-
Notifications
- Events that trigger notifications (opens in a new tab) (
CloudWatch Events
)- Comments
- On commits
- On pull requests
- Approvals
- Status changed
- Rule override
- Pull request
- Source updated
- Created
- Status changed
- Merged
- Branches and tags
- Created
- Deleted
- Updated
- Comments
- Targets
SNS
topicAWS Chatbot
(Slack)
- Events that trigger notifications (opens in a new tab) (
-
Triggers
Triggers
do not useCloudWatch Events
rules to evaluate repository events. They are more limited in scope.- Use case
- Send emails to subscribed users every time someone pushes to the repository.
- Notify an external build system to start a build after someone pushes to the main branch of the repository.
- Events
Push to existing branch
Create branch or tag
Delete branch or tag
- Target
SNS
Lambda
CodeBuild
-
When setting up
CodeBuild
projects to accessVPC
, choose privatesubnets
only. -
Need access to
S3
for code source, therefore 2 approachNAT Gateway
(additional charge)S3
Gateway Endpoint
-
Caching Dependencies (opens in a new tab)
-
S3
stores the cache in an
S3 bucket
that is available across multiple build hosts -
Local
stores a cache locally on a build host that is available to that build host only
-
Docker layer cache
Caches existing
Docker
layers so they can be reused. Requires privileged mode. -
Source cache
Caches
.git
metadata so subsequent builds only pull the change in commits. -
Custom cache
Caches directories specified in the
buildspec
file.
-
-
CodeDeploy
-
Application Revision
- A
revision
contains a version of the source filesCodeDeploy
will deploy to your instances or scriptsCodeDeploy
will run on your instances.
- A
-
- Configuration:
appspec.yml
must be present in the root directory of the application revision archive. files
section (opens in a new tab)- The paths used in
source
are relative to theappspec.yml
file, which should be at the root of your revision.
- The paths used in
- Configuration:
-
Compute platforms
EC2/On-Premises
- Requires installed and running
CodeDeploy
agent on instances - Requires an
IAM
instance profile (a Role) forEC2
instances (opens in a new tab)
- Requires installed and running
ECS
Lambda
-
Deployment types
-
In-place
-
EC2/On-Premises
(opens in a new tab) compute platform only -
Deployment configurations
- One at a time
- Half at a time
- All at once
-
-
Blue/green
-
Only
EC2
noton-premises
instances supportblue/green
deployment. -
All
Lambda
andECS
deployments areblue/green
. -
Deployment configurations
-
EC2
-
One at a time
Routes traffic to one instance in the replacement environment at a time.
-
-
-
All at once
-
Canary
Traffic is shifted in two increments,
10%
in the first increment, and the remaining90%
after5 / 15 minutes
. -
Linear
Traffic is shifted in equal increments (
10%
) with a fixed interval (1 / 3 minutes
).
-
-
-
All at once
-
Canary
Traffic is shifted in two increments,
10%
in the first increment, and the remaining90%
after5 / 10 / 15 / 30 minutes
. -
Linear
Traffic is shifted in equal increments (
10%
) with a fixed interval (1 / 2 / 3 / 10 minutes
).
-
-
-
-
-
Deployment Group
- A
deployment group
contains individuallytagged
instances,EC2
instances inEC2 Auto Scaling
groups, or both. EC2
instances must havetags
to be added into adeployment group
.
- A
-
CodeDeploy
agent-
The
CodeDeploy
agent is a software package that, when installed and configured on aninstance
, makes it possible for thatinstance
to be used inCodeDeploy
deployments. -
The
CodeDeploy
agent is required only if you deploy to anEC2/On-Premises
compute platform. -
Checking
CodeDeploy
agent service is installed and running (opens in a new tab)sudo service codedeploy-agent status
-
Logs on
EC2
Linux instance-
deployment log
/var/log/aws/codedeploy-agent/codedeploy-agent.log
-
scripts log
/opt/codedeploy-agent/deployment-root/deployment-group-ID/deployment-ID/logs/scripts.log
-
-
-
Deployment
-
-
CodeDeploy
rolls back deployments by redeploying a previously deployed revision of an application as a new deployment. -
CodeDeploy
first tries to remove from each participatinginstance
all files that were last successfully installed, namely the instances which caused the deployment failure, and all other untouched instances will be involved later. -
Automatic rollback
- The last known good version of an application revision is deployed.
-
Steps
-
First tries to remove from each participating instance all files that were last successfully installed.
-
In the case of detecting exsting files, the options are as follows.
- Fail the deployment
- Overwrite the content
- Retain the content
-
-
-
-
Resources
CodePipeline
-
In a default setup, a
pipeline
is kicked-off whenever a change in the configured pipeline source is detected.CodePipeline
currently supports sourcing fromCodeCommit
,GitHub
,ECR
, andS3
. -
When using
CodeCommit
,ECR
, orS3
as the source for a pipeline,CodePipeline
uses aCloudWatch Event
to detect changes in the source and immediately kick off a pipeline. -
When using
GitHub
as the source for a pipeline,CodePipeline
uses awebhook
to detect changes in a remote branch and kick off the pipeline. -
CodePipeline
also supports beginning pipeline executions based on periodic checks, although this is not a recommended pattern. -
To customize the logic that controls pipeline executions in the event of a source change, you can introduce a custom
CloudWatch Event
. -
The pipeline stops when it reaches the
manual approval
action. If anSNS
topicARN
was included in the configuration of the action, a notification is published to theSNS
topic, and a message is delivered to any subscribers to the topic or subscribed endpoints, with a link to review the approval action in theconsole
. -
Resources
ECR
-
Authentication (opens in a new tab)
- To authenticate
Docker
to anECR
registry withget-login-password
(opens in a new tab), run theaws ecr get-login-password
command. (Formerly, the command isget-login
, which has been deprecated but may still show up in the exam.)
- To authenticate
-
AWS - Reducing AWS Fargate Startup Times with zstd Compressed Container Images (opens in a new tab)
ECR - Cheatsheet
Docker login to ECR
aws ecr get-login-password --region <region> | \
docker login \
--username AWS \
--password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com
Describe repositories
aws ecr describe-repositories \
--query 'sort_by(repositories,&repositoryName)[].{Repo:repositoryName,URI:repositoryUri}' \
--output table
Describe images
local repoName=<repo-name>
aws ecr describe-images --repository-name $repoName \
--query 'reverse(sort_by(imageDetails,&imagePushedAt))[].{Repo:repositoryName,Tag:imageTags[] | [0],Digest:imageDigest,PushedAt:imagePushedAt}' \
--output table
Find images with the given digest
local repoName=<repo-name>
local sha256Hash=<sha256-hash>
aws ecr describe-images --repository-name $repoName \
--query 'imageDetails[?imageDigest==`sha256:$sha256Hash`].{Repo:repositoryName,Tag:imageTags[] | [0],Digest:imageDigest,PushedAt:imagePushedAt}' \
--output table
Find images with the given tag
local repoName=<repo-name>
local tagKeyword=<tagKeyword>
aws ecr describe-images --repository-name $repoName \
--query 'imageDetails[?contains(imageTags, $tagKeyword>)].{Repo:repositoryName,Tag:imageTags[] | [0],Digest:imageDigest,PushedAt:imagePushedAt}' \
--output table
ECS
-
Container Instance
- If you terminate a
container instance
in theRUNNING
state, thatcontainer instance
is automatically removed, or deregistered, from the cluster. However, if you terminate acontainer instance
in theSTOPPED
state, thatcontainer instance
isn't automatically removed from the cluster.
- If you terminate a
-
ECS Container Agent (opens in a new tab)
-
ECS_ENABLE_TASK_IAM_ROLE
Whether
IAM
roles
fortasks
should be enabled on thecontainer instance
fortask
containers with the bridge or default network modes.
-
-
EC2
Launch Type-
An
ECS
Cluster is a logical group ofEC2
instances, also calledcontainer instance
. -
Each
container instance
has anECS
container agent
(aDocker container
) installed. -
Container instance
can only useAmazon Linux AMI
-
ECS
container agent
registers thecontainer instance
to the cluster. -
ECS
container agent
configuration/etc/ecs/ecs.config
-
Load balancing
-
ALB
andNLB
supportsdynamic host port mapping
(opens in a new tab), allowing you to have multipletasks
from a single service on the samecontainer instance
. -
To enable
dynamic host port mapping
, host port must be set to0
orempty
intask definition
. -
CLB
does not allow you to run multiple copies of atask
on the sameinstance
because the ports conflict.
-
-
Task definition
(opens in a new tab)- A
task
is similar to apod
inKubernetes
. - Container definitions (opens in a new tab)
- Define one or multiple containers
- Standard parameters:
Name
,Image
,Memory
,Port Mappings
- Every
container
in atask definition
must land on the samecontainer instance
. - Need to specify resources needed
- Need to specify configuration specific to the
task
- Need to specify the
IAM
role that yourtask
should use
- A
-
Task placement (opens in a new tab)
-
-
binpack
Tasks
are placed on container instances so as to leave the least amount of unused CPU or memory to minimize the number of container instances in use. -
random
Random
places tasks on instances at random. This still honors the otherconstraints
that you specified, implicitly or explicitly. Specifically, it still makes sure thattasks
are scheduled on instances with enough resources to run them. -
spread
Tasks are placed evenly based on the specified value.
-
-
Constraint
(opens in a new tab)-
distinctInstance
Place each task on a different container instance.
-
memberOf
Place tasks on container instances that satisfy an
Cluster query
expression.
-
-
Cluster query language (opens in a new tab)
Cluster queries
are expressions for targeting container instances, which can be used intask placement memberOf constraint
.
-
-
-
Fargate
Launch Type- Fully managed
- Serverless
-
IAM
-
Service-Linked Role (for
ECS
) (opens in a new tab)- Granting
ECS
the permissions it requires to call otherAWS
services on your behalf.
- Granting
-
Task Execution
IAM Role
(forcontainer agent
) (opens in a new tab)- Use case
- Pulling image from
ECR
- Pulling image from
The
task
execution role grants theECS
container andFargate
agents permission to makeAWS
API
calls on your behalf. - Use case
-
ECS
Container InstanceIAM Role
(forcontainer instance
) (opens in a new tab)-
Container instances
that run theECS
containeragent
require anIAM
policy
androle
for the service to know that theagent
belongs to you. -
Containers
that are running on yourcontainer instances
have access to all of thepermissions
that are supplied to thecontainer instance
role throughinstance metadata
. -
Use case
- Register a
container
into a cluster
- Register a
-
-
IAM Role
forTasks
(forcontainers
in atask
) (opens in a new tab)- an
IAM role
that can be used by thecontainers
in atask
- an
-
-
Resources
EKS
-
Resources
Lambda
Lambda - Invocation Models
-
AWS Docs - Comparing Lambda invocation modes (opens in a new tab)
-
Invocation Type
(opens in a new tab)-
The
invocation type
can only be specified at the time of manually executing aLambda
function. ThisLambda
function execution is calledon-demand invocation
. -
InvocationType
parameter-
RequestReponse
Execute synchronously
-
Event
Execute asynchronously
-
DryRun
Test that the caller permits the invocation but does not execute the function.
-
-
Lambda - Invocation Models - synchronous
Synchronous
invocation (default) (opens in a new tab)
-
RPC style
-
Invocation Type
:RequestResponse
-
Services
ELB
(Application Load Balancer
)Cognito
Lex
Alexa
API Gateway
CloudFront
(Lambda@Edge
)Kinesis Data Firehose
-
Details about the function response, including errors, are included in the response body and headers.
Lambda - Invocation Models - asynchronous
Asynchronous
invocation (opens in a new tab)
-
Invocation Type
:Event
-
Services
S3
SNS
SES
CloudFormation
CloudWatch Logs
CloudWatch Events
CodeCommit
AWS Config
-
Lambda
adds events to a queue before sending them to your function. If your function does not have enough capacity to keep up with the queue, events may be lost. -
Suitable for services
producing events at a lower rate than the function can process
, as there is usuallyno message retention
and message loss would happen if function is overwhelmed. -
For higher throughput, consider using
SQS
orKinesis
andLambda
event source mapping. -
- Either a
SNS
topic or aSQS
queue, as the destination for all failed invocation events. - An alternative to an
on-failure destination
, but a part of a function's version-specific configuration, so it is locked in when you publish aversion
.
- Either a
-
Destinations
forasynchronous invocation
(opens in a new tab)-
Types
SQS
– A standardSQS
queueSNS
– ASNS
topicLambda
– ALambda
functionEventBridge
– AnEventBridge
event bus
-
You can configure condition of the destination to be
on success
oron failure
.
-
Lambda - event source mapping
Event source mapping
(poll-based) (opens in a new tab)
-
A
Lambda
integration setup for poll-based event sources (with data in potentially large volume) such asqueues
andstreams
. -
Lambda
pulls records from the data stream of event sources and invokes your function synchronously with an event that contains stream records.Lambda
reads records in batches and invokes your function to process records from the batch. -
Process items from a stream or queue in services that don't invoke
Lambda
functions directly -
Event source mappings
that read from astream
are limited by the number ofshards
in the stream. -
Services
SQS
DynamoDB Streams
Kinesis
MQ
MSK (Managed Streaming for Apache Kafka)
- Self-managed
Apache Kafka
-
Parallelization Factor
- Kinesis and DynamoDB Streams only
Lambda - authorization
-
Execution permissions
- Assigned to
Lambda function
- Enable the
Lambda function
to access otherAWS
resources in your account.
- Assigned to
-
Invocation permissions
- Assigned to
event source
- Enable the
event source
to communicate with yourLambda
function.
- Assigned to
Lambda - runtime
Custom runtime (opens in a new tab)
-
You can implement a
Lambda
custom runtime
in any programming language. -
A
runtime
is aprogram
that runs aLambda
function's handler method when the function is invoked. You can include aruntime
in your function'sdeployment package
in the form of an executable file namedbootstrap
. -
A
runtime
is responsible for running the function's setup code, reading the handler name from an environment variable, and reading invocation events from theLambda
runtimeAPI
. Theruntime
passes the event data to the function handler, and posts the response from the handler back toLambda
. -
The
runtime
can be included in your function'sdeployment package
, or in alayer
. -
Scripting language runtime such as
Node.js
andPython
runtime have better native support thanJava
, as some tooling support enables deploying source code directly. -
Resources
Lambda - execution environment lifecycle
Execution environment lifecycle (opens in a new tab)
-
Init
-
Happens at the time of the first function invocation
-
In advance of function invocations if you have enabled
provisioned concurrency
. -
3 Tasks
-
Extension Init
-
Runtime Init
-
Function Init
Runs the function’s initialization code (the code outside the main handler)
-
-
-
Invoke
-
Shutdown
Lambda - function deployment
-
Lambda
function's code consists of scripts or compiled programs and their dependencies. -
Deployment package
size limit (opens in a new tab)50 MB
(zipped, for direct upload)250 MB
(unzipped, including layers)
Lambda - function handler
-
The handler is a method inside the
Lambda
function that you create and include in your package. -
-
Async handlers
- If your code performs an asynchronous task, return a promise or
await
the promise to make sure that it finishes running
- If your code performs an asynchronous task, return a promise or
-
Non-async handlers
- Function execution continues until the event loop is empty or the function times out.
-
Lambda - function configuration
-
The total size of all environment variables doesn't exceed
4 KB
. -
Memory
- From
128 MB
to3008 MB
in64-MB
increments - You can only directly configure the memory for your function, and
Lambda
allocatesCPU
power in proportion to the amount of memory configured.
- From
-
Timeout
- Default is
3 seconds
, and max is15 minutes (900 seconds)
. AWS
charges based on execution time in100-ms increments
.
- Default is
-
Network
- Network configuration
default
VPC
- A
Lambda
function in yourVPC
has no internet access. - Deploying a
Lambda
function in a publicsubnet
doesn't give it internet access or a publicIP
. - Deploying a
Lambda
function in a privatesubnet
gives it internet access if you have aNAT Gateway / Instance
. - Use
VPC endpoints
to privately accessAWS
services without aNAT
.
- Network configuration
-
Concurrency
-
By default, the concurrent execution limit is enforced against the sum of the concurrent executions of all functions.
-
By default, the account-level concurrency within a given
Region
is set with1000
concurrent execution as a maximum to provide you1000
concurrent functions to execute. You can open a support ticket withAWS
to request an increase in your account level concurrency limit. -
Lambda
requires at least100
unreserved concurrent executions
per account. -
Concurrency = (average requests per second) * (average request duration in seconds)
-
Reserved concurrency
Applies to the entire
function
, including allversions
andaliases
-
Provisioned concurrency
(opens in a new tab)- To enable a function to scale without fluctuations in latency.
Provisioned concurrency
cannot exceedsreserved concurrency
.Provisioned concurrency
simply initializes the assigned capactity upfront to avoid a cold-start, hence without noticeable latency.
-
Parallelization Factor
(opens in a new tab)- For
stream
processing (event source mapping
),one
Lambda
function invocation processesone
shard
at a time, namelyParallelization Factor
is1
. Parallelization Factor
can be set to increase concurrentLambda
invocations for eachshard
, which by default is1
.
- For
-
-
-
Each
Lambda
functionversion
has a uniqueARN
. After you publish aversion
, it is immutable, so you cannot change it. -
A function
version
includes:- function code and all associated dependencies
Lambda runtime
that invokes the function- All of the function settings, including the
environment variables
- A unique
ARN
to identify the specificversion
of the function
-
-
-
An
alias
is a pointer to aversion
, and therefore it also has a uniqueARN
. Assign analias
to a particularversion
and use thatalias
in the application to avoid updating all references to the oldversion
. -
An
alias
cannot point to$LATEST
. -
Weighted alias
- An
alias
allows you to shift traffic between 2versions
based on specified weights (%).
- An
-
-
- A
layer
is a.zip file archive
that contains libraries, acustom runtime
, or other dependencies. Withlayers
, you can use libraries in your function without needing to include them in your deployment package. - A function can use up to
5
layers
at a time. The total unzipped size of the function and alllayers
can't exceed the unzipped deployment package size limit of250 MB
. Layers
are extracted to the/opt
directory in the function execution environment. Eachruntime
looks for libraries in a different location under/opt
, depending on the language.
- A
-
Environment variables (opens in a new tab)
-
X-Ray
-
_X_AMZN_TRACE_ID
X-Ray
tracing header -
AWS_XRAY_CONTEXT_MISSING
:RUNTIME_ERROR
(default),LOG_ERROR
Lambda
sets this toLOG_ERROR
to avoid throwing runtime errors from theX-Ray
SDK.
-
-
Lambda - monitoring
-
-
Invocations
the number of requests billed
-
Duration
the amount of time that your function code spends processing an event
-
Lambda - service integration
Using AWS Lambda with other services (opens in a new tab)
Step Functions
-
Workflow type is either
Standard
orExpress
(opens in a new tab), and cannot be changed once created. -
Standard
Workflow- Maximum execution time:
1 year
- Priced per
state transition
. Astate transition
is counted each time a step in your execution is completed.
- Maximum execution time:
-
Express
Workflow-
Maximum execution time:
5 minutes
-
Priced by
the number of executions
you run, their duration, and memory consumption. -
Types
- Synchronous
- Asynchronous
-
IAM
-
Global, not
Region
specific -
-
Format:
arn:partition:service:region:account:resource
-
Partition
Partition
identifies the partition that the resource is in. You cannot delegate access between accounts in differentpartitions
.- Supported partitions
aws
-AWS
Regionsaws-cn
- China Regionsaws-us-gov
-AWS GovCloud
(US) Regions
-
-
CLI
aws iam create-account-alias --account-alias <account-alias>
aws iam list-account-aliases
-
Tools
-
extract the
IAM
roles
andpolicies
from twoaccounts
, compare them, and report out the differences and statistics
-
Resources
-
Service Authorization Reference (opens in a new tab)
a list of the actions, resources, and condition keys that are supported by each
AWS
service
-
IAM - Access Analyzer
-
Helps identify the resources in your organization and accounts, such as
S3
buckets orIAM
roles, that are shared with an external entity, to find out unintended access to your resources and data. -
Preview Access (opens in a new tab)
CreateAccessPreview
ListAccessPreviewFindings
-
Validate Policy
ValidatePolicy
-
Resources
IAM - Access Advisor
- Use
last accessed information
to help identify unused permissions so that you can remove them. - Automate analyzing your permissions using IAM access advisor APIs (opens in a new tab)
- Refining permissions in AWS using last accessed information (opens in a new tab)
IAM - User
-
Uniquely identified identity
-
Long-term effective
-
Access
- Programmatic (
Access key ID
andSecret Access key
) - Web (
Web Management Console
)
- Programmatic (
IAM - Role
-
Similar to a
User
with attachedPermissions
policies -
Not uniquely identified, but a distinct identity with its own permissions
-
Temporarily effective for a designated timeframe
-
If an
IAM
user
assumes aRole
, only the policies of the assumedRole
are evaluated. Theuser
's ownpolicies
wouldn't be evaluated. -
Cannot be added to
IAM
groups -
Trust policy
specifies who can assume aRole
. -
An
IAM
role
is both an identity and a resource that supports resource-based policies (Trust policy
). -
Service-Linked
Role
-
Cross account access (opens in a new tab) can be given by allowing principals in account A to assume roles in account B.
-
When the
principal
and theresource
are in differentAWS accounts
, anIAM
administrator in the trusted account must also grant theprincipal entity
(user
orrole
) permission to access theresource
. -
Trust policy
to authorize the specified account to assume the role. Forroles
from a different account, thePrincipal ARN
contains itsAWS account ID
.{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": ["arn:aws:iam::<another-Account-ID>:role/<DesiredRoleName>"] }, "Action": "sts:AssumeRole" } ] }
-
Example
-
Account A
Trust policy
to authorize aRole
inAccount B
-
Account B
Identity-based policy
to authorize aUser
inAccount B
to access the resource inAccount A
-
-
-
Instance profile (opens in a new tab)
EC2
uses aninstance profile
as a container for anIAM role
.- If you use the
AWS Management Console
to create arole
forEC2
, the console automatically creates aninstance profile
and gives it the same name as therole
. - An
instance profile
is not anAWS CLI profile
.
IAM - Policy
-
Shared or not
-
Managed policies
- Can be attached to multiple identities
-
Inline policies
- Can be attached to only one identity
-
-
Policy Types
-
Identity-based policies
-
Policies
that you attach to anAWS
identity, such as auser
,group
of users, orrole
. -
Control what
actions
anentity
can perform, whichresources
they can use, and theconditions
in which they can use theresources
. -
AWS Managed Policies
Policies
that are created and managed byAWS
itself
-
Custom Managed Policies
Policies
that are created and managed by you in yourAWS
account
-
-
Resource-based policies
-
Policies
that you attach to a resource, specifying whichAPI actions
of theresource
are allowed. -
Different services have their unique
resource-based policies
. -
Resource-based policies
areinline policies
and there are no managedresource-based policies
. -
Trust policy
is aresource-based policy
forIAM Role
. -
Example:
arn:aws:iam::aws:policy/AWSLambdaExecute
-
-
-
Policy evaluation (opens in a new tab)
-
Final effective policies are the union of all policies with Explicit deny having the highest priority.
-
Actions or resources that are not explicitly allowed are denied by default (Implicit deny).
-
Order
- Explicit deny
- Explicit allow
- Implicit deny
-
-
Policy Variables (opens in a new tab)
- You can use
policy variables
as placeholders when you don't know the exact value in theResource
element and in string comparisons in theCondition
element.
- You can use
-
Preview Access (opens in a new tab)
-
Access Analyzer - CreateAccessPreview (opens in a new tab)
-
Access Analyzer - ListAccessPreviewFindings (opens in a new tab)
-
-
Validate Policy (opens in a new tab)
- Access Analyzer - ValidatePolicy (opens in a new tab)
-
Permission boundary (opens in a new tab)
- The
permissions boundary
for anIAM
entity (user
orrole
) sets the maximumpermissions
that the entity can have. - You can attach
permissions boundaries
only to auser
orrole
, not agroup
.
- The
AWS Organizations (opens in a new tab)
-
Features
Centralized management
of all of yourAWS accounts
Consolidated billing
for all member accountsHierarchical grouping
of your accounts to meet your budgetary, security, or compliance needsService control policies
(SCPs)Tag policies
AI services opt-out policies
Backup policies
- Free to use
Service control policies (SCP) (opens in a new tab)
- Affect only the member
accounts
in anOrganization
SCPs
offer central control over the maximum available permissions for allaccounts
in anOrganization
.SCPs
are similar toIAM
permission policies and use almost the same syntax. However, anSCP
never grants permissions. Instead,SCPs
are JSON policies that specify the maximum permissions for the affected accounts.SCP
can be used to restrict root account.
STS (Security Token Service) (opens in a new tab)
-
GetSessionToken
(opens in a new tab)- Returns a set of temporary credentials for an
AWS
account orIAM
user. The credentials consist of anaccess key ID
, asecret access key
, and asecurity token
. - Using the temporary credentials that are returned from the call,
IAM
users can then make programmatic calls to API operations that requireMFA
authentication. - Credentials based on account credentials can range from
900 seconds (15 minutes)
up to3600 seconds (1 hour)
, with a default of1 hour
.
- Returns a set of temporary credentials for an
-
AssumeRole
(opens in a new tab)Returns a set of temporary security credentials that you can use to access
AWS
resources that you might not normally have access to. These temporary credentials consist of anaccess key ID
, asecret access key
, and asecurity token
. -
DecodeAuthorizationMessage
(opens in a new tab)Decodes additional information about the authorization status of a request from an encoded message returned in response to an
AWS
request.
STS - Cheatsheet
STS - Get Caller Identity
-
GetCallerIdentity
returns details about theIAM
user orrole
whose credentials are used to call the operation.aws sts get-caller-identity
STS - View the maximum session duration setting for a role
S3
-
Data Consistency (opens in a new tab)
- Strong read-after-write (
GET
orLIST
) consistency forPUTs
andDELETEs
ofobjects
- Strong read consistency for
S3 Select
,S3 Access Control Lists
,S3 Object Tags
, andobject metadata
- Updates to a single
object key
are atomic, and there is no way to makeatomic updates
acrosskeys
. - High availability by replicating data across multiple servers within
AWS
data centers. Bucket
configurations have aneventual consistency
model.- Wait for
15 minutes
after enablingversioning
before issuing write operations (PUT
orDELETE
) onobjects
in thebucket
. S3
does not supportobject locking
for concurrent writers.
- Strong read-after-write (
S3 - Bucket
S3
lists allbuckets
, butbucket
is created specific to aregion
, butCross-Region Replication (CRR)
can be used to replicateobjects
(and their respective metadata and object tags) into otherRegions
.- Flat structure, folders in
S3
are simply shared name prefix Bucket
name must be globally unique, and cannbot be changed once created.Bucket
names can consist only of lowercase letters, numbers, dots (.
), and hyphens (-
).- To ensure
Bucket
names areDNS
-friendly, it's preferable to avoiddots
in names. Objects
inBucket
are private by default.- There are no limits to the number of prefixes in a
bucket
.
S3 - Bucket - Versioning
-
Buckets
can be in one of 3 statesUnversioned
(default)Versioning-enabled
Versioning-suspended
-
Once you enable
versioning
on abucket
, it can never return to theunversioned
state. You can, however,suspend versioning
on thatbucket
. -
If you have not enabled
versioning
,S3
sets the value of theversion ID
tonull
. -
Objects
stored in yourbucket
before you set the versioning state have aversion ID
ofnull
. -
Suspend
This suspends the creation of
object
versions for all operations but preserves any existingobject
versions.
S3 - Bucket - Lifecycle
-
Multiple
lifecycle rules
-
Permanent deletion
>Transition
>Creation of delete markers (versioned bucket)
-
Transition
S3 Glacier Flexible Retrieval
>S3 Standard-IA
/S3 One Zone-IA
-
S3 - Bucket - Object Lock
Object Lock (opens in a new tab)
-
Prevent
objects
from being deleted or overwritten for a fixed amount of time or indefinitely. -
Object Lock
works only inversioned buckets
, andretention periods
andlegal holds
apply to an individualobject version
. -
Use
Object Lock
to meet regulatory requirements that requireWORM
storage, or add an extra layer of protection against object changes and deletion. -
Retention mode
-
Compliance mode
The protected object version can't be
overwritten
ordeleted
byany user
, including theroot user
in your AWS account. When an object is locked incompliance mode
, its retention mode can't be changed, and its retention period can't be shortened. -
Governance mode
You protect objects against being deleted by
most users
, but you can still grant some users permission to alter theretention settings
ordelete the objects
if necessary. You can also usegovernance mode
to testretention-period
settings before creating acompliance-mode
retention period.
-
S3 - Bucket - Replication
Replication (opens in a new tab)
-
Both source and destination
buckets
must haveversioning
enabled. -
Destination
buckets
can be in differentRegions
or within the sameRegion
as the sourcebucket
. -
New objects
- Replicate new objects as they are written to the
bucket
- Use live replication such as
CRR
orSRR
CRR
andSRR
are implemented with the sameAPI
, and differentiated by thedestination
bucket
configuration.
- Replicate new objects as they are written to the
-
Existing objects
- Use
S3 Batch Operations
- Use
S3 - Bucket - Static Website Hosting
Static website hosting (opens in a new tab)
index document
must be specified, anderror document
is optional.- If you create a folder structure in your
bucket
, you must have anindex document
at each level. In each folder, theindex document
must have the same name, for example,index.html
. S3
website endpoints do not supportHTTPS
. UseCloudFront
in that case.- Access a website hosted in a
S3
bucket with a custom domain- The
Bucket
is configured as a static website. - Bucket name must match the domain name exactly.
- Add an
alias record
inRoute53
to route traffic for the domain to theS3 Bucket
- The
S3 - Bucket - Event Notifications
S3 Event Notifications (opens in a new tab)
- Destination
Lambda
functionSNS
topicSQS
standard
queue (FIFO
queue not supported)EventBridge
event bus
- If two writes are made to a single
non-versioned
object at the same time, it is possible that only a single event notification will be sent. - If you want to ensure that an event notification is sent for every successful write, you can enable
versioning
on your bucket. Withversioning
, every successful write will create a new version of your object and will also send an event notification.
S3 - Bucket - Management - Inventory
S3 Inventory
(opens in a new tab)
- Audit and report on the replication and encryption status of your objects for business, compliance, and regulatory needs.
- Generates inventories of the objects in the bucket on a
daily
orweekly
basis, and the results are published to a flat file. - The bucket that is inventoried is called the
source bucket
, and the bucket where the inventory flat file is stored is called thedestination bucket
. - The
destination bucket
must be in the same Region as thesource bucket
. S3 inventory
gives youa complete list of your objects
. This list will be published to thedestination bucket
, and can be given inParquet
,ORC
orCSV
formats, therefore can be analyzed withAthena
.
S3 - Bucket - Select
S3 Select
(opens in a new tab)
- Use a subset of
SQL
statements to filter the contents ofS3
objects
and retrieve just the subset of data that you need. - By using
S3 Select
to filter this data, you can reduce the amount of data thatS3
transfers, which reduces the cost and latency to retrieve this data. S3 Select
works onobjects
stored inCSV
,JSON
, orApache Parquet
format with compression ofGZIP
orBZIP2
.- You can only query one
object
at a time. - If you use
FileHeaderInfo.USE
, you can only reference column withcolumn name
. - Column name must be quoted with
"
if it contains special characters or is a reserved word. e.g.SELECT s."column name" FROM S3Object s
S3 - Bucket - Transfer Acceleration
Transfer Acceleration (opens in a new tab)
- Use the edge locations of
CloudFront
network to accelerate transfer between your client and the specifiedS3 bucket
. - Not recommended for small files or close proximity to the
S3
Region
.
S3 - Bucket - Analytics
S3 Analytics
(opens in a new tab)
- You use
storage class analysis
to observe yourdata access patterns over time
to gather information to help you improve the lifecycle management of yourSTANDARD_IA
storage. - Analyze storage access patterns to help you decide when to transition the right data to the right storage class.
S3 - Bucket - Access Points
Access Points (opens in a new tab)
-
Simplify managing data access at scale for shared datasets in
S3
, enabling different teams to accessshared data
withdifferent permissions
. -
Traits
-
Access points
arenamed network endpoints
attached tobuckets
that you can use to performS3 object
operations, such asGetObject
andPutObject
. -
For
S3 object operations
, you can use theaccess point ARN
in place of abucket name
. -
Each
access point
has distinct permissions and network controls thatS3
applies for any request that is made through thataccess point
. -
You can only use
access points
to perform operations onobjects
. -
S3 operations compatible with
access points
Access point compatibility with S3 operations (opens in a new tab)
-
S3 - Bucket - Access Points - Object Lambda
S3 Object Lambda (opens in a new tab)
-
ETL
withLambda
forS3
data retrieval API -
Uses
Lambda
functions to automatically process the output of standardS3
GET
,LIST
, orHEAD
requests. -
An
Object Lambda Access Point
is based on an existingS3 Access Point
and is used to invoke aLambda function
to processS3
objects
on the fly. -
Cannot make changes to the
Bucket
, only itsObjects
(opens in a new tab) -
Resources
- Object Lambda Features (opens in a new tab)
- AWS News Blog - Introducing Amazon S3 Object Lambda – Use Your Code to Process Data as It Is Being Retrieved from S3 (opens in a new tab)
- AWS News Blog - New – Use Amazon S3 Object Lambda with Amazon CloudFront to Tailor Content for End Users (opens in a new tab)
S3 - Object
-
At-Rest Encryption
-
S3
only supportssymmetric CMK
s, notasymmetric CMK
s. -
Server-side Encryption (opens in a new tab)
-
Adding the
x-amz-server-side-encryption
header to theHTTP
request to demand server-side encryption. -
- Use
AWS managed CMK
to generatedata key
for encryption, user intervention not needed x-amz-server-side-encryption: AES256
- Use
-
-
Use a
CMK
you created inKMS
to generatedata key
for encryption, requiring permission forKMS
access -
x-amz-server-side-encryption: aws:kms
-
When you upload an object, you can specify the
AWS KMS CMK
using thex-amz-server-side-encryption-aws-kms-key-id
header. If the header is not present in the request,S3
assumes theAWS managed CMK
. -
Permissions
-
kms:GenerateDataKey
(opens in a new tab)Returns a plaintext copy of the data key and a copy that is encrypted under a customer master key (CMK) that you specify.
-
kms:Decrypt
(opens in a new tab)Multipart
uploading needs this permission to decrypt the encrypted data key kept with the encrypted data as the plain text one is deleted after the first part is uploaded.
-
-
-
-
Provide your own
data key
upon every encryption and decryption action -
Must use
HTTPS
-
S3
does not store the encryption key you provide. Instead, it stores a randomly saltedHMAC
value of the encryption key to validate future requests. -
x-amz-server-side-encryption-customer-algorithm
must be
AES256
-
x-amz-server-side-encryption-customer-key
the 256-bit, base64-encoded encryption key
-
x-amz-server-side-encryption-customer-key-MD5
message integrity check to ensure that the encryption key was transmitted without error
-
-
-
Client-side Encryption (opens in a new tab)
- Encryption and decryption happen on the client side with
S3
only saving your data. - You can use your
CMK
stored locally orCMK
stored inKMS
.
- Encryption and decryption happen on the client side with
-
As an analogy, suppose you go to work on any business day, and need to figure out how to have lunch.
Client-side encryption
is like having lunch at home.SSE-S3
is like ordering takeaway from your office.SSE-KMS
is like having lunch at your company's onsite canteen.SSE-C
is like bringing your lunch from home to work.
-
-
S3 Batch Operations
S3 Batch Operations (opens in a new tab)
- Large-scale batch operations on
S3
objects EB
scale- Requires
S3 Inventory
to be enabled
- Large-scale batch operations on
-
Uploading
- When a file is over
100 MB
,multipart
upload is recommended as it will upload many parts in parallel, maximizing the throughput of your bandwidth and also allowing for a smaller part to retry in case that part fails. - You can upload a single object up to
5 GB
. More than5 GB
, you must usemultipart
upload. Part
size:5 MB to 5 GB
. There is no size limit on the last part of yourmultipart
upload.Object
size:0 to 5 TB
- To perform a
multipart
upload with encryption using anAWS KMS
key, the requester must havekms:GenerateDataKey
permissions to initiate the upload, andkms:Decrypt
permissions to upload object parts. The requester must havekms:Decrypt
permissions so that newly uploaded parts can be encrypted with the same key used for previous parts of the same object.
- When a file is over
-
Quota
3500
PUT/COPY/POST/DELETE
and5500
GET/HEAD
requests per second per prefix in a bucket
- No limits to the number of prefixes in a bucket
S3 - Object - Presigned URL
Presigned URL (opens in a new tab)
-
Grant URL caller temporary access to the specified
S3
object without authentication and authorization. -
Generated programmatically
-
GET
for downloading andPUT
for uploading -
As a general rule,
AWS
recommends usingbucket policies
orIAM policies
for access control.ACLs
is a legacy access control mechanism that predatesIAM
. -
S3
stores access logs asobjects
in abucket
.Athena
supports analysis ofS3 objects
and can be used to queryS3
access logs.
S3 - Security
S3 - Security - Block public access
Block public access (opens in a new tab)
A shortcut switch to block all public access granted in Bucket Policy
or ACL
s.
S3 - Security - ACL
Access Control List (opens in a new tab)
- Can define which
AWS
accounts or groups are granted access and the type of access. - Can manage permissions of
Objects
.
S3 - Bucket - Permissions - CORS
- To configure your
bucket
to allow cross-origin requests, you create aCORS
configuration.
S3 - Storage Lens
Cloud storage analytics solution with support for AWS Organizations
to give you organization-wide visibility into object storage, with point-in-time metrics and trend lines as well as actionable recommendations.
All these things combined in an interactive dashboard will help you discover anomalies, identify cost efficiencies, and apply data protection best practices across accounts.
S3 - Storage classes
Storage classes (opens in a new tab)
S3 - Storage classes - S3 Standard
S3 - Storage classes - S3 Intelligent-Tiering
S3 Intelligent-Tiering (opens in a new tab)
-
Characteristics
-
No retrieval charges
-
Automatic storage cost savings when data access patterns change, without performance impact or operational overhead
-
Access tiers
-
Frequent Access
tierObjects uploaded to
S3 Intelligent-Tiering
are stored in theFrequent Access
tier. -
Infrequent Access
tierObjects not accessed for 30 consecutive days are automatically moved to the
Infrequent Access
tier. -
Archive Instant Access
tierObjects not accessed for 90 consecutive days are automatically moved to the
Archive Instant Access
tier.
-
-
Frequent Access
,Infrequent Access
, andArchive Instant Access
tiers have the same low-latency and high-throughput performance ofS3 Standard
-
The
Infrequent Access
tier saves up to40%
on storage costs -
The
Archive Instant Access
tier saves up to68%
on storage costs
-
-
Use cases
- Suitable for objects with unknown or changing access patterns
- Suitable for objects equal to or larger than
128 KB
-
Anti patterns
- Objects smaller than
128 KB
will not be monitored and will always be charged at theFrequent Access
tier rates, with no monitoring and automation charge. - Data retrieval or modification is more frequent than the transition intervals.
- Access patterns are predictable and you can manage the storage classes transitions explicitly.
- Objects smaller than
S3 - Storage classes - S3 Standard-IA
- For data that is accessed less frequently, but requires rapid access when needed.
- Incurs a data retrieval fee
S3 - Storage classes - S3 One Zone-IA (S3 One Zone-Infrequent Access)
- Stores data in a single
AZ
and costs 20% less thanS3 Standard-IA
- Incurs a data retrieval fee
S3 on Outposts
S3 - CLI Cheatsheet
-
List buckets and objects (opens in a new tab)
aws s3 ls
-
Create a bucket (opens in a new tab)
aws s3 mb s3://<
bucket-name
>
-
Upload or copy objects (opens in a new tab)
aws s3 cp <local file path>/<S3 URI> <S3 URI>
-
Delete a bucket (opens in a new tab)
aws s3 rb s3://<
bucket-name
>
-
Delete an object (opens in a new tab)
aws s3 rm <target>
-
Options
--recursive
S3 Glacier
S3 Glacier (opens in a new tab)
-
Glacier Select (opens in a new tab)
-
Unlike
S3 Select
, does not support compressedCSV
orJSON
files -
AWS News Blog - S3 Select and Glacier Select – Retrieving Subsets of Objects (opens in a new tab)
-
-
AWS Docs - Storage classes for archiving objects (opens in a new tab)
S3 Glacier - Instant Retrieval
- Ideal for long-lived archive data accessed once or twice per quarter with
instant retrieval in milliseconds
- The
lowest cost
archive storage withmilliseconds retrieval
- Offer a cost savings compared to the
S3 Standard-IA
, with the same latency and throughput performance as theS3 Standard-IA
. - Higher data access costs than
S3 Standard-IA
- Min storage duration of
90 days
S3 Glacier - Flexible Retrieval
-
Ideal for long-lived archive data
accessed once a year
withretrieval times of minutes to hours
-
Min storage duration of
90 days
-
Archive Retrieval Options
-
Expedited:
1–5 minutes
- Incurs a data retrieval fee
-
Standard:
3–5 hours
- Incurs a data retrieval fee
-
Bulk:
5–12 hours
- Free data retrieval
-
S3 Glacier - Deep Archive
- Ideal for long-lived archive data
accessed less than once a year
withretrieval times of hours
- Default retrieval time of
12 hours
- Min storage duration of
180 days
- Incurs a data retrieval fee
CloudFront
-
Distribution (opens in a new tab)
-
Origin Settings
-
S3
origins -
Custom origins (
EC2
,ELB
)-
Origin Protocol Policy (opens in a new tab)
HTTP Only
HTTPS Only
Match Viewer
-
-
-
Cache Behaviour Settings
-
Viewer Protocol Policy (opens in a new tab)
HTTP and HTTPS
Redirect HTTP to HTTPS
HTTPS Only
-
-
-
Lambda@Edge
(opens in a new tab)Lambda
functions ofPython
andNode.js
runtime can be deployed atCloudFront
edge locationsLambda@Edge
allows you to pass each request through aLambda
to change the behaviour of the response.- Authorization@Edge (opens in a new tab): You can use
Lambda@Edge
to help authenticate and authorize users for the premium pay-wall content on your website, filtering out unauthorized requests before they reach yourorigin
infrastructure.
-
Origin access (opens in a new tab)
-
Benefits
- Restricts access to the AWS origin so that it's not publicly accessible
-
Origin type
-
S3
-
OAC / Origin Access Control
-
S3 SSE-KMS
-
Dynamic requests (PUT and DELETE) to S3
-
-
OAI / Origin Access Identity (legacy)
- Restricting Access to
S3
content by using anOrigin Access Identity
, a specialCloudFront
user, which the targetS3
bucket can reference inbucket policy
. Once set up, users can only access files throughCloudFront
, not directly from theS3
bucket.
- Restricting Access to
-
-
MediaStore
-
-
-
Serving private content (opens in a new tab)
-
To use
signed URLs
orsigned cookies
, you need asigner
. Asigner
is either a trusted key group (Recommended) that you create inCloudFront
, or anAWS
account that contains aCloudFront
key pair (can only be created by root user). -
You cannot use either
signed URLs
orsigned cookies
if originalURL
containsExpires
,Policy
,Signature
,Key-Pair-Id
query parameters. -
Signed URL
(opens in a new tab)- Uses a
JSON
policy statement (canned or custom) to specify the restrictions of thesigned URL
- Use
signed URLs
when you want to restrict access to individual files. - Use
signed URLs
when your users are using a client that doesn't supportcookies
.
- Uses a
-
Signed cookies
(opens in a new tab)- Use
signed cookies
when you want to provide access to multiple restricted files. - Use
signed cookies
when you don't want to change your currentURLs
.
- Use
-
-
Using HTTPS with CloudFront (opens in a new tab)
- Both connections between
viewers
andCloudFront
, and connections betweenCloudFront
andorigin
can be encrypted by usingHTTPS
. - You can't use a self-signed
SSL
certificate forHTTPS
communication betweenCloudFront
and yourorigin
, and the certificate must be managed byACM
. - You don't need to add an
SSL
certificate if you only requireHTTPS
for communication between theviewers
andCloudFront
(default certificate provided byCloudFront
).
- Both connections between
-
Availability
Origin failover
(opens in a new tab)- an
origin group
with twoorigins
: aprimary
and asecondary
. If theprimary origin
is unavailable, or returns specificHTTP
response status codes that indicate a failure,CloudFront
automatically switches to thesecondary origin
. - To set up
origin failover
, you must have adistribution
with at least 2origins
.
- an
RDS
AWS Docs - RDS (Relational Database Service) (opens in a new tab)
-
Authentication
IAM
database authentication (opens in a new tab)- Only works with
MySQL
andPostgreSQL
. - Instead of password, an
authentication token
is generated byRDS
when you connect to aDB instance
. - Each
authentication token
has a lifetime of15 minutes
. - Recommended as a temporary and personal access
- Only works with
-
Read Replicas (opens in a new tab) (for Scalability)
-
Operates as a
DB instance
that only allows read-only connections; applications can connect to aread replica
just as they would to anyDB instance
. -
Asynchronous replication to a
Read Replica
-
Uses a different
DB connection
string than the one used by themaster instance
To be able to switch at runtime, it'd need 2 connection pools in the application respectively .
-
Can be promoted to the master
-
-
Multi-AZ deployments (opens in a new tab) (for High Availability)
-
Synchronous replication to a
standby instance
in a differentAZ
-
In case of an infrastructure failure,
RDS
performs an automatic failover to the standby instance (or to aread replica
in the case ofAmazon Aurora
), so that you can resume database operations as soon as the failover is complete. -
The endpoint for your DB instance remains the same after a failover
-
The
failover
mechanism automatically changes theDNS
CNAME
record of theDB
instance to point to thestandby instance
. -
The
standby instance
cannot be used as aread replica
. -
Multi-AZ DB instance deployment
1
standby DB instance- failover support
no read traffic
support
-
Multi-AZ DB cluster deployment
3
DB instances- failover support
- read traffic support
-
Resources
-
-
Snapshot
-
When you perform a restore operation to a point in time or from a DB
snapshot
, a newDB instance
is created with a new endpoint (the oldDB instance
can be deleted if so desired). This is done to enable you to create multipleDB instances
from a specificDB snapshot
or point in time. -
Automated backups
are limited to a singleRegion
whilemanual snapshots
andread replicas
are supported across multipleRegion
s. -
Manual
snapshot
- When you delete a
DB instance
, you can create a final DBsnapshot
upon deletion. - Manual
snapshots
are kept after the deletion of theDB instance
.
- When you delete a
-
Automated
snapshot
- Configurable retention period with
7 day by default up to 35 days
- Cannot be manually deleted, automatically deleted when the DB
instance
is deleted - Stored in
S3
- Storage of automated
snapshots
are free as long as the DBinstance
is running. If the DBinstance
is stopped, the storage of automatedsnapshots
would be charged as per standard pricing.
- Configurable retention period with
-
-
Encryption
-
Encrypting a
DB instance
(opens in a new tab)RDS
provides at-rest data encryption, so all logs, backups, andsnapshots
are encrypted.RDS
uses anAWS
KMS
CMK
to encrypt these resources.- For
Oracle
orSQL Server
,RDS
also supports encrypting aDB instance
withTDE
(Transparent Data Encryption
).TDE
is aDB built-in feature
and supports both in-transit and at-rest data encryption, but forSQL Server
, onlyEnterprise Edition
supportsTDE
.
-
Encrypting a connection to a
DB instance
(opens in a new tab)- Use
SSL/TLS
from your application to encrypt a connection to aDB instance
. Each DB engine has its own process for implementingSSL/TLS
.
- Use
-
-
Monitoring
- Enhanced Monitoring (opens in a new tab)
RDS
providesmetrics
in real time for theOS
that yourDB instance
runs on.Enhanced Monitoring
metrics
are stored in theCloudWatch Logs
instead of inCloudwatch Metrics
.- After you have enabled
Enhanced Monitoring
for yourDB instance
, you can view themetrics
for yourDB instance
usingCloudWatch Logs
, with eachlog stream
representing a singleDB instance
being monitored. CloudWatch
gathersmetrics
aboutCPU utilization
from thehypervisor
for aDB instance
, andEnhanced Monitoring
gathers itsmetrics
from anagent
on theinstance
.
- Enhanced Monitoring (opens in a new tab)
RDS - Aurora
AWS Docs - Aurora (opens in a new tab)
- Serverless, fully managed
RDBMS
compatible withMySQL
andPostgreSQL
. - Up to
5 times
the throughput ofMySQL
and up to3 times
the throughput ofPostgreSQL
without requiring changes to most of your existing applications. - Up to
15 read replica
- Automatic backup
RDS - RDS Proxy
RDS Proxy (opens in a new tab)
- Establishes a
database connection pool
andreuses connections
in this pool. - Makes applications more resilient to database failures by automatically connecting to a standby DB instance while preserving application connections.
RDS - Cheatsheet
List clusters
aws rds describe-db-clusters \
--query 'sort_by(DBClusters,&DBClusterIdentifier)[].{ClusterID:DBClusterIdentifier, ClusterARN:DBClusterArn, Port:Port, Engine:Engine, Version:EngineVersion, Status:Status}' \
--output table
List DB instances
aws rds describe-db-instances \
--query 'sort_by(DBInstances,&DBInstanceIdentifier)[].{InstanceID:DBInstanceIdentifier, InstanceARN:DBInstanceArn, Engine:Engine, Version:EngineVersion, Status:DBInstanceStatus}' \
--output table
DynamoDB
- Schemaless, you can only specify
keys
upon creation of tables,non-key attributes
can only be added as part of new records.
DynamoDB - Availability
Region
specific- Data replicated among multiple
AZ
s in aRegion
DynamoDB - Table Class
-
Standard
- Offers lower throughput costs than
DynamoDB Standard-IA
and is the most cost-effective option for tables where throughput is the dominant cost.
- Offers lower throughput costs than
-
Standard-IA
- Offers lower storage costs than
DynamoDB Standard
, and is the most cost-effective option for tables where storage is the dominant cost. - When storage exceeds
50% of the throughput (reads and writes) cost
of a table using theDynamoDB Standard
table class, theDynamoDB Standard-IA
table class can help you reduce your total table cost.
- Offers lower storage costs than
DynamoDB - Primary Key
-
Paritition key
(required)or
Partition key
(required) +Sort key
(optional), combination must be unique. -
Write Sharding
(opens in a new tab)-
To better distribute writes across a
partition key
space inDynamoDB
is to expand the space. -
Random Sharding (opens in a new tab)
add
a random number
to the end of thepartition key
values. -
Calculated Sharding (opens in a new tab)
use a number that you can calculate based upon something that you want to query on.
-
DynamoDB - GSI
- To speed up queries on
non-key attributes
- An index with a
partition key
and asort key
that can be different from those on the base table - It is considered global because queries on the index can span all of the data in the
main table
across all partitions. - The
main table
's primary key attributes are always projected into an index. Up to 20
GSI
/ table (soft limit)- Can be created after table creation
RCU
andWCU
provisioned independently ofmain table
, and therefore aQuery
operation on aGSI
consumesRCU
from theGSI
, not themain table
. When you change items in a table, theGSI
on that table are also updated. These index updates consumeWCU
from theGSI
, not from themain table
.- If the writes are throttled on the
GSI
, the write activity on themain table
will also be throttled. - Only support
eventual consistent reads
(cannot providestrong consistency
) - In a
DynamoDB table
, each key value must beunique
. However, the key values in aGSI
do not need to beunique
.
DynamoDB - LSI
- An index with the same
Partition key
but a differentSort key
Up to 5
LSI
/ table (hard limit)- Cannot be created after table creation
- Use the
WCU
andRCU
of the base table - No special throttling considerations
- Supports both
strong
andeventual
consistent reads - A
LSI
lets you query over a single partition, as specified by thepartition key
value in the query.
DynamoDB - Read Consistency
-
Read committed
isolation level -
base table
Strongly consistent read
Eventually consistent read
-
LSI
Strongly consistent read
Eventually consistent read
-
GSI
Eventually consistent read
-
DynamoDB streams
Eventually consistent read
DynamoDB - Capacity
-
Throughput mode:
Provisioned
orOn-Demand
-
Read Capacity Unit (RCU)
1 RCU
=1
strongly consistent read/s or2
eventually consistent read/s, for an item up to4 KB
in size.- For item size more than
4 KB
, it would take an additionalRCU
. - For item size less than
4 KB
, it would still take oneRCU
. - Calculation
strongly consistent
- Round data up to nearest 4
- Divide data by 4
- Multiplied by number of reads
eventual consistent
- Round data up to nearest 4
- Divide data by 4
- Multiplied by number of reads
- Divide final number by 2
- Round up to the nearest whole number
-
Write Capacity Unit (WCU)
1 WCU
=1
write/s for an item up to1 KB
in size.- For item size more than
1 KB
, it would take an additionalWCU
. - For item size less than
1 KB
, it would still take1 WCU
. - Calculation
- Round data up to nearest 1
- Multiplied by number of writes
-
If your application consumes more throughput than configured in the provisioned throughput settings, application requests start throttling.
-
Adaptive Capacity (opens in a new tab)
- Boost Throughput Capacity to High-Traffic
Partitions
- Enables your application to continue reading and writing to hot partitions without being throttled, provided that traffic does not exceed your table’s total provisioned capacity or the partition maximum capacity.
- Isolate Frequently Accessed Items
- If your application drives disproportionately high traffic to one or more items,
adaptive capacity
rebalances your partitions such that frequently accessed items don't reside on the same partition.
- If your application drives disproportionately high traffic to one or more items,
- Boost Throughput Capacity to High-Traffic
-
To retrieve consumed capacity by an operation, parameter
ReturnConsumedCapacity
(opens in a new tab) can be included in the request toAPI
, with 3 options:INDEXES
,TOTAL
,NONE
.
DynamoDB - Query
Query
requires thepartition key
value and returns all items with it. Optionally, you can provide asort key
attribute and use a comparison operator to refine the search results.- A
filter expression
determines which items within theQuery
results should be returned to you. This happens after the itmes are returned therefore doesn't improve performance. - A single
Query
operation can retrieve a maximum of1 MB
of data. Query
results are always sorted by thesort key
value, by default in ascending order.
DynamoDB - Scan
- Reads every item in a table or a secondary index
- By default, a
Scan
operation returns all of the data attributes for every item in the table or index. - If the total number of scanned items exceeds the maximum dataset size limit of
1 MB
(default page size), thescan
stops and results are returned to the user as aLastEvaluatedKey
value to continue thescan
in a subsequent operation. - a
Scan
operation reads an entirepage
(by default,1 MB
), you can reduce the impact of thescan
operation by setting a smallerpage
size. - Each
Query
orScan
request that has a smallerpage
size uses fewer read operations and creates a "pause" between each request. Scan
usesLimit
parameter to set thepage
size for your request.Parallel Scan
- The table size is
20 GB
or larger. - The table's provisioned
RCU
is not being fully used. - Default sequential
Scan
operations are too slow.
- The table size is
DynamoDB - TTL
- Must identify a specific attribute name that the service will look for when determining if an item is eligible for expiration.
- The attribute should be a
Number
data type containing time in epoch format. - Once the timestamp expires, the corresponding item is deleted from the table in the background.
DynamoDB - Data type
- How to store temporal data (opens in a new tab)
- String
- Human-friendly (
ISO-8601
format)
- Human-friendly (
- Number
- Can be used for
TTL
- Can be used for
- String
DynamoDB - DAX
AWS Docs - DynamoDB Accelerator (DAX) (opens in a new tab)
-
Characteristics
- A fully managed in-memory write through cache for
DynamoDB
that runs in as a cluster in yourVPC
. - Should be provisioned in the same
VPC
as theEC2
instances that are accessing it.
- A fully managed in-memory write through cache for
-
Pros
- Fastest response times possible to microseconds
- Apps that read a small number of items more frequently
- Apps that are read intensive
-
Cons
- Reads must be
eventually consistent
, therefore apps requiringstrongly consistent
reads cannot useDAX
- Not suitable for apps that do not require microsecond read response times
- Not suitable for apps that are write intensive, or that do not perform much read activity
- Reads must be
-
Supports following read operations in
eventually consistent read
mode-
Item Cache (opens in a new tab)
GetItem
BatchGetItem
-
Query Cache (opens in a new tab)
Query
Scan
-
-
The following
DAX
API operations are consideredwrite-through
BatchWriteItem
UpdateItem
DeleteItem
PutItem
-
Misc
ElastiCache
can be used with other DBs and applications, whileDAX
is forDynamoDB
only.
DynamoDB - Transaction
- Supports transactions via the
TransactWriteItems
andTransactGetItems
API calls. Transactions
let you query multiple tables at once and are an all-or-nothing approach.
DynamoDB - Global table
Global table
(opens in a new tab)
- HA and fault tolerance
- Lower latency for users in different
Regions
- With
global tables
you can specify theRegions
where you want the table to be available.DynamoDB
performs all of the necessary tasks to create identical tables in theseRegions
and propagate ongoing data changes to all of them. DynamoDB global tables
use a “last writer wins” reconciliation between concurrent updates, and therefore doesn't supportoptimistic locking
.
DynamoDB - Streams
-
Capture
item-level changes
in your table, and push the changes to aDynamoDB stream
. You then can access the change information through theDynamoDB Streams API
. -
View type
-
Keys only
Only the key attributes of the modified item
-
New image
The entire item, as it appears after it was modified
-
Old image
The entire item, as it appeared before it was modified
-
New and old image
Both the new and the old images of the item
-
-
Streams
do not consumeRCU
s. -
All data in
DynamoDB Streams
is subject to a24-hour
lifetime.
DynamoDB - Conditional operations
-
Put
,Delete
andUpdate
can be performed with conditions specified withConditional Expressions
(opens in a new tab). -
The internal implementation of
optimistic locking
withinDynamoDBMapper
usesconditional update
andconditional delete
support provided byDynamoDB
. -
Optimistic Locking with Version Number (opens in a new tab)
- Use
@DynamoDBVersionAttribute
annotation to mark the property
- Use
DynamoDB - Atomic counter
Atomic counter (opens in a new tab)
- A numeric attribute that is incremented unconditionally, without interfering with other write requests
- The numeric value increments each time you call
UpdateItem
. - An
atomic counter
would not be appropriate where overcounting or undercounting can't be tolerated.
DynamoDB - Quota
- The
maximum item size
is400 KB
, which includes bothattribute name binary length (UTF-8 length)
andattribute value lengths (binary length)
. The attribute name counts towards the size limit.
DynamoDB - Point-in-time recovery (PITR)
Continuous backup
withper-second granularity
so that you can restore toany given second in the preceding 35 days
.- Using
PITR
, you can back up tables withhundreds of TB of data
, withno impact on the performance or availability
of your production applications.
DynamoDB - Resources
- NoSQL Design for DynamoDB (opens in a new tab)
- DynamoDB Cheatsheet (opens in a new tab)
- DynamoDB Streams Use Cases and Design Patterns (opens in a new tab)
- 10 DynamoDB Limits You Need To Know (opens in a new tab)
ElastiCache
-
ElastiCache
is only accessible to resource operating within the sameVPC
to ensure low latency. -
Caching Strategies (opens in a new tab)
-
Lazy Loading
- On-demand loading of data from database if a cache miss occurs
-
Write-Through
- Update cache whenever data is written to the database, ensuring cache is never stale.
-
TTL
specifies the number of seconds until the key expires.
-
-
Memcached
- Simple key/value store, only supports string, therefore suitable for static, small data such as HTML code fragments
- Multi-threaded, scaling will cause loss of data
- Marginal performance advantage because of simplicity
-
Redis
- Supports advanced data structures
- Single-threaded, scaling causes no loss of data
- Finer-grained control over eviction
- Supports persistence, transactions and replication
-
Use case
-
Resources
Route 53
-
Supported
DNS
record types (opens in a new tab)-
A
(Address) recordsAssociate a domain name or subdomain name with the
IPv4
address of the corresponding resource -
AAAA
(Address) recordsAssociate a domain name or subdomain name with the
IPv6
address of the corresponding resource -
CAA
A
CAA
record specifies whichcertificate authorities
(CAs
) are allowed to issue certificates for a domain or subdomain. Creating aCAA
record helps to prevent the wrongCAs
from issuing certificates for your domains. -
- Reroute traffic from one domain name (example.net) to another domain name (example.com)
- The
DNS
protocol does not allow you to create aCNAME
record for the top node of aDNS
namespace (zone apex
).
-
DS
A
delegation signer
(DS
) record refers a zone key for a delegated subdomain zone. You might create aDS
record when you establish a chain of trust when you configureDNSSEC
signing. -
MX
(Mail server) recordsRoute traffic to mail servers
-
NAPTR
A
Name Authority Pointer
(NAPTR
) is a type of record that is used byDynamic Delegation Discovery System
(DDDS
) applications to convert one value to another or to replace one value with another. -
NS
An
NS
record identifies the name servers for the hosted zone. -
PTR
A
PTR
record maps anIP
address to the correspondingdomain name
. -
SOA
A start of authority (
SOA
) record provides information about a domain and the correspondingAmazon Route 53 hosted zone
. -
SPF
Deprecated,
TXT
is recommended instead. -
SRV
SRV
records are used for accessing services, such as a service for email or communications. -
TXT
A
TXT
record contains one or more strings that are enclosed in double quotation marks (").
-
-
Alias
records (opens in a new tab)- Unlike a
CNAME
record, you can create analias
record at the top node of aDNS
namespace (zone apex
). - To route domain traffic to an
ELB load balancer
, useRoute 53
to create analias record
that points to your load balancer. - A
zone apex
record is aDNS
record at the root of aDNS
zone, and thezone apex
must be anA
record.
- Unlike a
-
Routing policy
-
Simple routing policy
Use for a single resource that performs a given function for your domain, for example, a web server that serves content for the example.com website.
-
Failover routing policy
Use when you want to configure active-passive failover.
-
Geolocation routing policy
Use when you want to route traffic based on the location of your users.
-
Geoproximity routing policy
Use when you want to route traffic based on the location of your resources and, optionally, shift traffic from resources in one location to resources in another.
-
Latency routing policy
Use when you have resources in multiple
Regions
and you want to route traffic to theregion
that provides the best latency. -
Multivalue answer routing policy
Use when you want
Route 53
to respond toDNS
queries with up to eight healthy records selected at random. -
Weighted routing policy
Use to route traffic to multiple resources in specified proportions.
-
-
TTL
DNS
records cache has aTTL
. AnyDNS
update will not be visible untilTTL
has elapsed.TTL
should be set to strike a balance between how long the value should be cached vs how much pressure should go on theDNS
.
-
Health checks
- Health checks that monitor an endpoint
- Health checks that monitor other health checks (calculated health checks)
- Health checks that monitor
CloudWatch alarms
Route 53 Resolver (opens in a new tab)
-
A
Route 53 Resolver
automatically answersDNS
queries for:-
Local
VPC
domain names forEC2
instancese.g.
ec2-192-0-2-44.compute-1.amazonaws.com
-
Records in
private hosted zones
e.g.
acme.example.com
-
For
public domain names
,Route 53 Resolver
performs recursive lookups against public name servers on the internet.
-
Route53 - Cheatsheet
Update the given DNS record(s)
aws route53 change-resource-record-sets \
--hosted-zone-id <hosted-zone-id> \
--change-batch \
'{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "<old-DNS-name>",
"Type": "CNAME",
"TTL": 300,
"ResourceRecords": [
{
"Value": "<new-DNS-name>"
}
]
}
}
]
}'
Get the key-signing keys (KSKs) public key and DS record of your parent hosted zone
# Reference: https://repost.aws/knowledge-center/route-53-configure-dnssec-domain
aws route53 get-dnssec --hosted-zone-id <hosted-zone-id>
CloudWatch
CloudWatch Events (Amazon EventBridge
)
-
Rule
-
Event Source
- Timing
- Event Pattern
- Schedule
- Supported services
- Events directly supported by
CloudWatch
(opens in a new tab), sent by services having direct support forCloudWatch Events
- Events delivered via
CloudTrail
, which logAPI
actions with finer granularity, but requiring correspondingCloudTrail
logging being enabled
- Events directly supported by
- Timing
-
Target
- A variety of
AWS
services
- A variety of
-
-
AWS
service events are free -
Custom events (
PutEvents
actions) may incur additional charges. -
EventBridge
- supports a lot more targets, meaning you can integrate between a wider variety of services
- Its cross-account delivery capability further amplifies its reach. It’s easy to distribute events to
Kinesis
,Step Functions
, and many other services running in anotherAWS
account. - supports native
AWS
events as well as third-party partner events. - supports content-based filtering.
- supports input transformation.
- has built-in schema discovery capabilities.
CloudWatch Metrics
-
Metrics
areRegion
based. -
Namespace
- A
namespace
is a container formetrics
, andmetrics
in differentnamespaces
are isolated from each other, such asAWS/EC2
- AWS services that publish CloudWatch metrics (opens in a new tab)
- A
-
Dimension
- A
dimension
is a unique identifier ofmetrics
, such asinstanceID
. - Up to 10
dimensions
permetric
, and eachdimension
is defined by a name and value pair.
- A
-
Custom Metrics (opens in a new tab)
- Can only be published to
CloudWatch
using theAWS CLI
or anAPI
. - Use
PutMetricData
API action programmatically
- Can only be published to
-
Metric Math (opens in a new tab)
- Enables you to query multiple
CloudWatch metrics
and use math expressions to create new time series based on thesemetrics
.
- Enables you to query multiple
-
Resolution
- Predefined
Metrics
produced byAWS
services arestandard resolution
. - When you publish a
Custom Metric
, you can define it as eitherstandard resolution
orhigh resolution
. - Standard resolution:
1 minute
granularity - High resolution:
1 second
granularity
- Predefined
-
-
CloudWatch
AWS/EC2
namespace (opens in a new tab)-
These metrics are collected by
CloudWatch Metrics
under namespaceAWS/EC2
. 2 modes for metrics collection,basic monitoring
ordetailed monitoring
.-
Basic Monitoring
EC2
sends metric data toCloudWatch
in5-minute
periods at no charge.
-
Detailed Monitoring
-
EC2
sends metric data toCloudWatch
in1-minute
periods for an additional charge. -
Enable
detailed monitoring
usingAWS CLI
aws ec2 monıtor-ınstances --ınstance-ıds <instance-IDs>
-
-
-
-
Metrics collected by the
CloudWatch Agent
(opens in a new tab)- For metrics not available under namespace
AWS/EC2
, they can be collected byCloudWatch Agent
. - The collected metrics is available under namespace
CWAgent
inCloudWatch Metrics
. CloudWatch Agent
also can collect logs.
- For metrics not available under namespace
-
-
List
AWS
services publishingCloudWatch Metrics
(opens in a new tab)aws cloudwatch list-metrics [--namespace <namespace>] [--metric-name <metric-name>]
CloudWatch Alarms
-
Metric
-
An
Alarm
watches a singlemetric
over a specified time period, and performs one or more specifiedactions
, based on the value of themetric
relative to a threshold over time. -
A value of the metric is a data point.
-
Period
forAWS Metrics
cannot be lower than 1 minute. -
Alarm
on High ResolutionCustom Metrics
Period
of10 or 30 seconds
(High ResolutionAlarm
(opens in a new tab) with additional charge)Period
of1 minute
(regularAlarm
with no charge)
Alarm Period Metrics Standard Resolution ( 60 Seconds
)Metrics High Resolution ( 1 Second
)10 Seconds ❌ ✅ (additional charge) 30 Seconds ❌ ✅ (additional charge) 60 Seconds ✅ ❌
-
-
Evaluation (opens in a new tab)
-
Period
The length of time in seconds to evaluate the metric or expression to create each individual
data point
for analarm
-
Evaluation Periods
The number of the most recent
periods
, ordata points
, to evaluate when determiningalarm
state. -
Data points to alarm
Define the number of
data points
within the evaluationperiod
that must be breaching to cause thealarm
to go toALARM
state.
-
-
Action
- a notification sent to a
SNS
topic Auto Scaling
actionsEC2
actions (only applicable toEC2 Per-Instance Metrics
)
- a notification sent to a
-
States
-
ALARM
The
metric
is within the defined threshold -
INSUFFICIENT
The
metric
is beyond the defined threshold -
OK
The
alarm
has only just been configured, themetric
is unavailable, or we do not have sufficient data for themetric
to determine thealarm
state.
-
CloudWatch Logs
-
CloudWatch
logs never expire by default. -
Log data retention can be configured on
Log group
level. -
Log groups
: arbitrary name, usually representing an application -
Log stream
: instances within application / log files / containers -
Synthetics (opens in a new tab)
-
Canary
-
Canaries are scripts written in Node.js or Python. They create Lambda functions in your account that use Node.js or Python as a framework. Canaries work over both HTTP and HTTPS protocols.
-
Blueprints (opens in a new tab)
- Heartbeat Monitor
- API Canary
- Broken Link Checker
- Visual Monitoring
- Canary Recorder
- GUI Workflow
-
-
-
Resources
CloudWatch - Logs Insights
CloudWatch - Application Signals
CloudWatch - Application Signals - Synthetics Canaries
- Synthetic monitoring works by issuing automated, simulated transactions from a robot client to your application in order to mimic what a typical user might do.
- Based on
Puppeteer
CloudWatch - Cheatsheet
List all metrics
aws cloudwatch list-metrics
List all metrics of a namespace
-
aws cloudwatch list-metrics --namespace <namespace>
e.g.
aws cloudwatch list-metrics --namespace "AWS/Route53"
CloudTrail
Trail
- Applies to all
Region
s, recording events in allRegion
s - Applies to one
Region
, recording events in thatRegion
only Organization
trail (opens in a new tab)- If you have created an
Organization
, you can also create atrail
that will log all events for allAWS
accounts in thatOrganization
. Organization
trails can apply to allRegions
or oneRegion
.Organization
trails must be created in the management account.- Member accounts will be able to see the
Organization
trail, but cannot modify or delete it. - By default, member accounts will not have access to the log files for the
Organization
trail in theS3
bucket.
- If you have created an
- Applies to all
- Events (opens in a new tab)
- Management events
- Data events (additional charges apply)
CloudTrail Insights
events
CloudTrail - Data Events
- High-volume activities and include operations such as S3 object level API operations and Lambda function invoke API.
CloudTrail - CloudTrail Lake
CloudTrail Lake (opens in a new tab)
- Converts existing events in row-based
JSON
format toORC
format
X-Ray
-
A distributed tracing solution, especially for apps built using a microservices architecture
-
Segment
- At a minimum, a
segment
records thename
,ID
,start time
,trace ID
, andend time
of the request. - A
segment
document can be up to64 KB
and contain a wholesegment
withsubsegments
, a fragment of asegment
that indicates that a request is in progress, or a singlesubsegment
that is sent separately. You can sendsegment
documents directly toX-Ray
by using thePutTraceSegments API
. - When you instrument your application with the
X-Ray SDK
, theSDK
generatessegment
documents for you. Instead of sendingsegment
documents directly toX-Ray
, theSDK
transmits them over a localUDP
port to theX-Ray daemon
.
- At a minimum, a
-
Subsegment
-
Subsegment
provides more granular timing information and details about downstream calls that your app made to fulfill the original request. -
Subsegments
can contain othersubsegments
, so a customsubsegment
that recordsmetadata
about an internal function call can contain other customsubsegments
andsubsegments
for downstream calls. -
A
subsegment
records a downstream call from the point of view of the service that calls it. -
Field
namespace
-aws
forAWS
SDK
calls;remote
for other downstream calls.
-
-
Service Graph
is a flow chart visualization of average response for microservices and to visually pinpoint failure. -
Trace
collects allSegment
s generated by a single request so you can track the path of requests through multiple services.Trace ID
inHTTP
header (Tracing header
) is namedX-Amzn-Trace-Id
.
-
Sampling
is an algorithm that decides which requests should be traced. By default,X-Ray
records the first request each second and5%
of any additional requests. -
Annotations
- Use
Annotations
(opens in a new tab) to record information onSegment
s orSubsegment
s that you want indexed for search. Annotations
support 3 data types:String
,Number
andBoolean
.- Keys must be alphanumeric in order to work with
filters
. Underscore is allowed. Other symbols and whitespace are forbidden and ignored. X-Ray
indexes up to50
annotations
pertrace
.
- Use
-
Use
Metadata
to record data you want to store in thetrace
but don't need to use for searchingtraces
. -
Daemon
-
X-Ray
deamon gathers raw segment data, and relays it to theX-Ray
API
-
The
daemon
works in conjunction with theX-Ray SDKs
and must be running so that data sent by theSDKs
can reach theX-Ray
service. -
By default listens on
UDP port 2000
-
-r, --role-arn
: Assume the specifiedIAM role
to uploadsegment
s to a different account. -
ECS
create a
Docker
image that runs theX-Ray
daemon, upload it to aDocker
image repository, and then deploy it to yourECS
cluster.
-
-
Instrumentation (opens in a new tab)
- Automatic
- Manual
KMS
-
Multi-tenant
key store management service operated byAWS
. -
KMS
can use its ownhardware security modules
(HSMs
) or a customer managedCloudHSM
key store. -
Region
specific, a key that is created in oneregion
can't be used in anotherregion
-
KMS
centrally stores and manages the encryption keys calledKMS Key
, andKMS Keys
are stored in plain text, by default issymmetric
. -
Encrypt
,Decrypt
andReEncrypt
API
actions are designed to encrypt and decryptdata keys
, as they useKMS Key
and can only encrypt up to4 KB
data. -
Data over
4 KB
can only be encrypted withEnvelope Encryption
using adata key
. -
Types of
KMS Key
Description Customer-managed AWS-managed AWS-owned Key creation customer AWS
on behalf of customerAWS
Key usage Customer can control key usage through the KMS
andIAM
policycan be used only with specific AWS
services whereKMS
is supportedimplicitly used by AWS
to protect customer data; customer can't explicitly use itKey rotation manually configured by customer rotated automatically once a year rotated automatically by AWS
without any explicit mention of the rotation scheduleKey deletion can be deleted can't be deleted can't be deleted User access controlled by the IAM
policycontrolled by the IAM
policycan't be accessed by users Key access policy managed by customer managed by AWS
N/A -
Encryption options in
KMS
-
AWS managed keys
- Encryption Method (
AWS
managed) - Keys Storage (
AWS
managed) - Keys Management (
AWS
managed)
- Encryption Method (
-
Customer managed keys
- Encryption Method (Customer managed)
- Keys Storage (
AWS
managed,CloudHSM
) - Keys Management (Customer managed)
-
Custom key stores
- Encryption Method (Customer managed)
- Keys Storage (Customer managed)
- Keys Management (Customer managed)
-
-
API
-
Encrypts plaintext into ciphertext by using a
KMS CMK
. -
Decrypts ciphertext that was encrypted by a
KMS CMK
. -
GenerateDataKey (opens in a new tab)
-
Generates a unique symmetric
data key
for client-side encryption, including a plaintext copy of thedata key
and a copy that is encrypted under aCMK
that you specify. -
To encrypt data outside of
KMS
:- Use the
GenerateDataKey
operation to get adata key
. - Use the plaintext
data key
(in thePlaintext
field of the response) to encrypt your data outside ofKMS
(Using any 3rd party cryptography library) - Erase the plaintext
data key
from memory. - Store the encrypted
data key
(in theCiphertextBlob
field of the response) with the encrypted data.
- Use the
-
To decrypt data outside of
KMS
:- Use the
Decrypt
operation to decrypt the encrypteddata key
. The operation returns a plaintext copy of thedata key
. - Use the plaintext
data key
to decrypt data outside ofKMS
. - Erase the plaintext
data key
from memory.
- Use the
-
-
GenerateDataKeyWithoutPlaintext (opens in a new tab)
The same result as
GenerateDataKey
, only without the plaintext copy of thedata key
.
-
-
Symmetric and asymmetric CMKs (opens in a new tab)
-
All
AWS
services that encrypt data on your behalf require a symmetricCMK
. -
Symmetric key
- Encrypt / Decrypt
-
Asymetric key
Encrypt
/Decrypt
Sign
/Verify
- Doesn't support automatic key rotation
- The standard
asymmetric encryption
algorithms thatKMS
uses do not support anencryption context
.
-
KMS - Cross account access
Allowing users in other accounts to use a KMS key (opens in a new tab)
-
Cross-account
access requires permission in thekey policy
of theKMS key
and in anIAM policy
in the external user's account.- Add a
key policy statement
in thelocal account
- Add
IAM policies
in theexternal account
- Add a
-
Cross-account
permission is effective only for certainAPI
operations
CloudHSM
- AWS Docs - AWS CloudHSM (opens in a new tab)
Single-tenant
hardware security module withcomplete control
- Customer operated
- Can be used as a
custom key store
forKMS
AWS Config
- By default, the configuration recorder records all supported resources in the
Region
whereAWS Config
is running. AWS Config Rules
(opens in a new tab)AWS Config Rules
represent your ideal configuration settings.AWS Config
continuously tracks the configuration changes. Any resource violating arule
will be flagged as non-compliant.
- Costs
- You are charged service usage fees when
AWS Config
starts recording configurations. - To control costs, you can stop recording by stopping the configuration recorder. After you stop recording, you can continue to access the configuration information that was already recorded. You will not be charged
AWS Config
usage fees until you resume recording.
- You are charged service usage fees when
Secrets Manager
- Automatic secrets rotation without disrupting applications
Service Catalog
-
AWS Docs - AWS Service Catalog Documentation (opens in a new tab)
-
Centrally manage and govern your curated
IaC templates
-
Product
- CloudFormation
- HashiCorp Terraform Cloud
- External (such as Terraform OSS)
Systems Manager (formerly SSM)
Automation (opens in a new tab)
Automation
helps you to build automated solutions to deploy, configure, and manageAWS
resources at scale.
Parameter Store (opens in a new tab)
- Centralized configuration data management and secrets management
- You can store values as plain text (
String
) or encrypted data (SecureString
). - For auditing and logging,
CloudTrail
capturesParameter Store
API
calls. Parameter Store
usesKMS CMKs
(opens in a new tab) to encrypt and decrypt the parameter values ofSecureString
parameters when you create or change them.- You can use the
AWS
managedCMK
thatParameter Store
creates for your account or specify your own customer managedCMK
.
Parameter Store - Cheatsheet
Search for a parameter with name containing the given keyword
local keyword=<keyword>
aws ssm describe-parameters --parameter-filters "Key=Name,Option=Contains,Values=$keyword" \
--query 'sort_by(Parameters,&Name)[]' --output table
CloudFormation
-
-
Use a
JSON
orYAML
file calledTemplate
to specify a declarative, static definition ofAWS
service stack. -
The
Template
file must be uploaded toS3
before being used. -
Parameters
Parameter
Type (opens in a new tab)String
Number
List<Number>
CommaDelimitedList
- AWS-Specific Parameter Types (opens in a new tab)
SSM
Parameter Types (opens in a new tab)
- You use the
Ref
intrinsic function to reference aParameter
, andAWS CloudFormation
uses theParameter
's value to provision the stack. You can referenceParameter
from theResources
andOutputs
sections of the same template. Pseudo parameters
Pseudo parameters
areParameters
that are predefined byCloudFormation
.- Use them the same way as you would a
Parameter
, as the argument for theRef
function. - Their names start with
AWS::
such asAWS::Region
.
-
Resources
- The only mandatory section
-
Conditions
- The optional
Conditions
section contains statements that define the circumstances under which entities are created or configured. - Other sections such as
Resource
andOutput
can reference the conditions defined inCondition
section. - Use
Condition function
(opens in a new tab) to define conditions.
- The optional
-
Mappings
- The optional
Mappings
section matches a key to a corresponding set of named values, essentially a Map using String as key. Fn::FindInMap
!FindInMap [ MapName, TopLevelKey, SecondLevelKey ]
- The optional
-
Outputs
- To share information between stacks,
export
a stack's output values. Other stacks that are in the sameAWS
account andRegion
can import the exported values. - To export a stack's output value, use the
Export
field in theOutput
section of the stack's template. To import those values, use theFn::ImportValue
function in the template for the other stacks. - Exported output names must be unique within your
Region
.
- To share information between stacks,
-
Intrinsic function (opens in a new tab)
Fn::Ref
(opens in a new tab)- The intrinsic function
Ref
returns the value of the specifiedParameter
orResource
. - When you
Ref
the logical ID of anotherResource
in your template,Ref
returns what you could consider as a default attribute for that type ofResource
. So usingRef
for anEC2
instance will return theinstance ID
,Ref
anS3
bucket, it will return thebucket name
.
- The intrinsic function
Fn::GetAtt
(opens in a new tab): TheFn::GetAtt
intrinsic function returns the value of an attribute from a resource in the template.Fn::FindInMap
(opens in a new tab): The intrinsic functionFn::FindInMap
returns the value corresponding to keys in a two-level map that is declared in theMappings
section.Fn::ImportValue
(opens in a new tab): The intrinsic functionFn::ImportValue
returns the value of an output exported by another stack. You typically use this function to create cross-stack references.Fn::Join
(opens in a new tab): The intrinsic functionFn::Join
appends a set of values into a single value, separated by the specified delimiter. If a delimiter is the empty string, the set of values are concatenated with no delimiter.Fn::Sub
(opens in a new tab): The intrinsic functionFn::Sub
substitutes variables in an input string with values that you specify.
-
Helper scripts (opens in a new tab)
CloudFormation
providesPython
helper scripts that you can use to install software and start services on anEC2
instance that you create as part of your stack.
-
-
-
Change set (opens in a new tab)
Change sets
allow you to preview how proposed changes to astack
might impact your running resources.- Similar to a
diff
to thestack
.
-
-
StackSets
extends the functionality ofstacks
by enabling you to create, update, or deletestacks
across multiple accounts andregions
with a single operation.
-
CLI
-
- This command is only needed when there is local artifacts.
- The command performs the following tasks:
- Packages the local artifacts (local paths) that your
CloudFormation
template references. - Uploads local artifacts, such as source code for an
Lambda
function or aSwagger
file for anAPI Gateway REST API
, to anS3
bucket. Note it is the local artifacts being uploaded, not the template. - Returns a copy of your template, replacing references to local artifacts with the
S3
location where the command uploaded the local artifacts.
- Packages the local artifacts (local paths) that your
-
Deploys the specified
CloudFormation
template by creating and then executing achange set
.
-
-
Resources
- AWS Documentation - CloudFormation User Guide - Template Reference (opens in a new tab)
- How do I delete an AWS CloudFormation stack that's stuck in DELETE_FAILED status? (opens in a new tab)
- Building CI/CD pipeline for Cloudformation templates
SQS (Simple Queue Service)
-
A queue from which consumers pull data pushed by producers.
-
Messages more than
256 KB
(opens in a new tab) must be sent with theSQS Extended Client Library for Java
, which usesS3
for message storage, supporting payload size up to2 GB
. -
Number of messages (
up to 10
) can be specified before retrieving. -
SQS
message retention period ranges from1 minute
to14 days
, by default4 days
. -
Visibility timeout
(opens in a new tab)- After a message is polled by a consumer, it becomes
invisible
to other consumers. - Message
visibility timeout
is the time for consumer to process the message, and it is30 seconds
by default. - If not deleted within the
visibility timeout
window, the message will becomevisible
to other consumers again. ChangeMessageVisibility
action can be used to prolongvisibility timeout
window.- If
visibility timeout
is too high, and consumer crashes meanwhile, reprocessing will take time. - If
visibility timeout
is too low, consumers may get duplicate messages.
- After a message is polled by a consumer, it becomes
-
Delivery delay
(opens in a new tab)- Delay happens before message being consumed.
- If you create a delay queue, any messages that you send to the queue remain invisible to consumers for the duration of the delay period. The default (minimum) delay for a queue is
0 seconds
. The maximum is15 minutes
.
-
SQS
providesshort polling
andlong polling
to receive messages from a queue. By default, queues useshort polling
.Long polling
decreases the number of API calls made toSQS
while increasing the efficiency and latency of your application.Long polling
is preferable toshort polling
.Long polling
can have a wait time from1
to20
second.
-
Queue type
-
Standard queues
- Default queue type
- Almost unlimited throughput,
up to 120000 in-flight messages
- at-least-once message delivery, requiring
manual deduplication
- Out-of-order message delivery
-
FIFO queue
- Throughput:
3000 messages / second
,up to 20000 in-flight messages
- Queue name must end with
.fifo
. - exactly-once message delivery
Message ordering
viamessage grouping
- Ordering across groups is not guaranteed.
- Messages that share a common
message group ID
will be in order within the group.
Deduplication
- If you retry the
SendMessage action
within the5-minute
deduplication interval,SQS
doesn't introduce any duplicates into the queue. - If a message with a particular
message deduplication ID
is sent successfully, any messages sent with the samemessage deduplication ID
are accepted successfully but aren't delivered during the5-minute
deduplication interval. - If your application sends messages with unique message bodies, you can enable content-based deduplication.
- If you retry the
- Cannot subscribe to a
SNS
topic
- Throughput:
-
-
Dead-letter queue (DLQ)
- The
DLQ
of aFIFO queue
must also be aFIFO queue
. - The
DLQ
of astandard queue
must also be astandard queue
. - The
DLQ
and its corresponding queue must be in the same region and created by the same AWS account. Redrive policy
Redrive policy
specifies the source queue, theDLQ
, and the conditions under whichSQS
moves messages from the former to the latter if the consumer of the source queue fails to process a message a specified number of times.- As long as a consumer starts polling, the message
Receive count
will increment by1
no matter the processing is successful or not, thereforeReceive count
is essentially receive attempt count. - If a message
Receive count
is more than the specifiedMaximum receives
, the message will be sent to the specifiedDLQ
. SQS
counts a message you view in theAWS Management Console
against the queue’sredrive policy
, because every attempt to view a message in the queue requiresPoll for messages
, and that will incrementReceive count
.
- The
-
Resources
SNS
- Max message size:
256 KB
, extended client library supporting2 GB
.
SNS - Topic
- A
Topic
allows multiple receivers of the message to subscribe dynamically for identical copies of the same notification. - By default,
SNS
offers10 million subscriptions per Topic and 100,000 Topics per account
.
SNS - Subscription
-
A subscriber receives messages that are published only after they have subscribed to the
Topic
. TheTopic
s do not buffer messages. -
When several
SQS
s act as a subscriber, a publisher sends a message to anSNS
topic and it distributes this topic to manySQS
queues in parallel. This concept is calledfanout
.
Cognito
-
User pool
(opens in a new tab)- User directory and access control for your application
- Sign-up, sign-in and related authentication functionality
-
Identity pool
(opens in a new tab)Identity pools
provide temporaryAWS
credentials for:- Unauthenticated guests
- Users who have been authenticated and received a token.
- Access to
AWS
services - Specific to your
AWS
account
-
Cognito Sync
(opens in a new tab)-
Synchronizing application data across devices
-
AppSync
is a modern replacement forCognito Sync
. -
Cognito Streams
(opens in a new tab)gives developers control and insight into their data stored in
Cognito
-
Cognito Events
(opens in a new tab)allows you to execute an
Lambda
function in response to important events inCognito
.
-
API Gateway
-
REST API
-
Stage variables
- A
stage
is a named reference to a deployment, which is a snapshot of theAPI
. Stage variables
are name-value pairs that you can define as configuration attributes associated with a deployment stage of aREST API
. They act likeenvironment variables
and can be used in yourAPI
setup andmapping templates
.- A
stage variable
can be used anywhere in amapping template
:${stageVariables.<variable_name>}
- A
-
Integration
type (opens in a new tab)-
AWS
(Lambda
custom integration)expose
AWS
service actions, must configure both theintegration request
andintegration response
. -
AWS_PROXY
(Lambda
proxy integration)-
This is the preferred integration type to call a
Lambda
function throughAPI Gateway
and is not applicable to any otherAWS
service actions, includingLambda
actions other than the function-invoking action. -
In
Lambda
proxy integration (opens in a new tab),API Gateway
requires the backendLambda
function to return output according to the followingJSON
format.{ "isBase64Encoded": true|false, "statusCode": httpStatusCode, "headers": { "headerName": "headerValue", ... }, "multiValueHeaders": { "headerName": ["headerValue", "headerValue2", ...], ... }, "body": "..." }
-
-
HTTP
expose
HTTP
endpoints in the backend, must configure both theintegration request
andintegration response
. -
HTTP_PROXY
expose
HTTP
endpoints in the backend, but you do not configure theintegration request
or the `integration response. -
MOCK
API Gateway
return a response without sending the request further to the backend, useful for testing integration set up.
-
-
- Integration timeout:
50 milliseconds
to29 seconds
for all integration types.
- Integration timeout:
-
API Gateway
responses (opens in a new tab)-
502 Bad Gateway
- Usually an incompatible output returned from a
Lambda
proxy integration backend - Occasionally for out-of-order invocations due to heavy loads.
- Usually an incompatible output returned from a
-
504 INTEGRATION_TIMEOUT
-
504 INTEGRATION_FAILURE
-
-
-
Canary release (opens in a new tab)
Total API traffic is separated at random into a production release and a
canary release
with a pre-configured ratio. -
Mapping template
- A script expressed in
Velocity Template Language (VTL)
and applied to the payload usingJSONPath
expressions to perform data transformation.
- A script expressed in
-
API cache
API Gateway
caches responses from your endpoint for a specifiedTTL
period, in seconds.- Default
TTL
is 300 seconds, andTTL=0
means caching is disabled. - Client can invalidate an
API Gateway
cache entry by specifyingCache-Control: max-age=0
header, and authorization can be enabled to ignore unauthorized requests.
-
Throttling
- Server-side throttling limits are applied across all clients.
- Per-client throttling limits are applied to clients that use
API keys
associated with yourusage plan
as client identifier.
-
Usage plan
-
Uses
API keys
to identify API clients and meters access to the associated API stages for each key. -
Configure throttling limits and quota limits that are enforced on individual client
API keys
. -
Throttling
-
Rate
- Number of requests per second that can be served
- The
rate
is evenly distributed across given time period.
-
Burst
- Maximum number of concurrent request submissions that API Gateway can fulfill at any moment without returning
429 Too Many Requests
error responses Burst
essentially means the maxium number of requests that can be queued for processing. OnceBurst
is exceeded, request will be dropped.
- Maximum number of concurrent request submissions that API Gateway can fulfill at any moment without returning
-
As an analogy, imagine you are in a bank branch waiting to be served,
Rate
is the number of customers that are being served at that same time.Burst
is the number of customers that can wait in a queue in the branch lobby. How long the queue can be is limited by the lobby space. Therefore if there are more customers not able to queue in the lobby, they must wait outside or choose another time to come to the branch.
-
-
-
Security
-
- Authentication:
IAM
- Authorization:
IAM
- Signature version 4 signing (opens in a new tab)
- Authentication:
-
Cognito
user pool (opens in a new tab)- Authentication:
Cognito
user pool - Authorization:
API Gateway
methods - Seamless integration, no custom code needed
- Authentication:
-
Lambda
authorizer (opens in a new tab)-
Authentication: 3rd-party (invoked by
Lambda
authorizer) -
Authorization:
Lambda
function -
Authorizer type
-
TOKEN
authorizerToken-based
Lambda
authorizer receives the caller's identity in a bearer token, such as aJWT
or anOAuth
token. -
REQUEST
authorizerRequest parameter-based
Lambda
authorizer receives the caller's identity in a combination of headers, query string parameters,stageVariables
, and$context
variables.WebSocket
only supportsREQUEST
authorizer.
-
-
-
-
-
4XXError
number of client-side errors captured in a given period
-
5XXError
number of server-side errors captured in a given period
-
Count
total number of
API
requests in a given period -
IntegrationLatency
the responsiveness of the backend
-
Latency
the overall responsiveness of your
API
calls -
CacheHitCount
&CacheMissCount
optimize cache capacities to achieve a desired performance.
-
-
CORS
-
To enable
CORS
support, you may or may not need to implement theCORS
preflight response depending on the situation.-
Lambda
orHTTP
non-proxy integrations andAWS
service integrationsManual adding
CORS
response headers could be needed -
Lambda
orHTTP
proxy integrationsManual adding
CORS
response headers is required
-
-
-
Resources
SAM
-
The declaration
Transform: AWS::Serverless-2016-10-31
is required forSAM
template files. -
Globals
section is unique toSAM
templates. -
Resource type
AWS::Serverless::Api
API Gateway
AWS::Serverless::Application
- Embeds a serverless application
AWS::Serverless::Function
- Lambda function
AWS::Serverless::HttpApi
- API Gateway HTTP API
AWS::Serverless::LayerVersion
- Creates a
Lambda
LayerVersion that contains library or runtime code needed by aLambda
Function.
- Creates a
AWS::Serverless::SimpleTable
- a
DynamoDB
table with a single attribute primary key.
- a
AWS::Serverless::StateMachine
- an
Step Functions
state machine
- an
-
Installation
-
Notes
- Use
SAM CLI
for localLambda
function development. (sam local invoke
) - Don't use
SAM CLI
for deployment as it creates additional resources. - Use
CloudFormation
for unified deployment and provisioning. - Use container image for deployment but not for local development as it's slow to build image,
IntelliJ
also does not support debuggingLambda
function packaged as an image.
- Use
-
Resources
CDK (Cloud Development Kit)
-
Assets
Assets
are local files, directories, or Docker images that can be bundled into AWS CDK libraries and apps; eg: a directory that contains the handler code for an AWS Lambda function.Assets
can represent any artifact that the app needs to operate. -
Bootstrapping
- Deploying AWS
CDK
apps into an AWS environment (a combination of an AWS account and region) may require that you provision resources the AWSCDK
needs to perform the deployment. These resources include anS3
bucket for storing files andIAM
roles that grant permissions needed to perform deployments. The process of provisioning these initial resources is calledbootstrapping
. cdk bootstrap aws://<Account-ID>/<Region>
- Deploying AWS
Billing and Cost Management
Free Tier
usage summary (opens in a new tab) can be found underBilling Management Console
.- Consolidated billing for AWS Organizations (opens in a new tab)
- You can use the
consolidated billing
feature inAWS Organizations
to consolidate billing and payment for multiple AWS accounts.
- You can use the
Savings Plans (opens in a new tab)
-
Types
- Compute
- EC2 Instance
- SageMaker
-
Pricing
- No upfront
- Partial upfront
- All upfront
Code Samples
Java project scaffolding
-
Maven
mvn -B archetype:generate \ -DarchetypeGroupId=software.amazon.awssdk \ -DarchetypeArtifactId=archetype-lambda \ -Dservice=s3 \ -Dregion=US_EAST_1 \ -DgroupId=cq.aws \ -DartifactId=playground-aws
Best Practices
-
- Both
keys
andvalues
are case sensitive. - Using
Tags
to index resources, so they can be found easily. - Typical tags
- Name
- Project
- Environment
- Version
- Owner
- Both
Resources
-
AWS Documentation - AWS Code Sample Catalog (opens in a new tab)
-
AWS Documentation - AWS General Reference (opens in a new tab)
AWS Service
endpoints
andquotas
-
AWS Documentation - Service Authorization Reference (opens in a new tab)
Service Authorization Reference
provides a list of theactions
, resources, and condition keys that are supported by each AWS service. You can specify actions, resources, and condition keys inIAM
policies to manage access to AWS resources.