Takeaway
Takeaway - Security
-
Data Encryption / Decryption
- Usually refers to
data at restencryption / decryption, in which case users need to explicitly specify the encryption key (symmetric). - Since the encryption key needs to be specified explicitly,
data at restencryption isnot enabled by default. Data in transitencryption isenabled by defaultand does not need user intervention, but users must adoptTLSsupported 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 & RestoreRPO/RTO: Hours- Lower priority use cases
- Provision all AWS resources after event
- Restore backups after event
- Cost
$
-
Pilot LightRPO/RTO: 10s of minutes- Data live
- Services idle
- Provision some AWS resources and scale after event
- Cost
$$
-
Warm standbyRPO/RTO: Minutes- Always running, but smaller
- Business critical
- Scale AWS resources after event
- Cost
$$$
-
Multi-siteRPO/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 CLIuses apage sizeof1000and retrievesall available items. -
If
all available itemsare more thanpage size, multipleAPIcalls are made untilall available itemsare returned. -
Parameters
-
--no-paginateReturn only the first page of results, therefore single
APIcall -
--page-sizeSpecify the number of items in a single page (by default
1000) -
--max-itemsSpecify the total number of items returned (by default
all available items) -
--starting-tokenWhen
--max-itemsspecifies a number smaller thanall available items, the output will include aNextTokenretrieving 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 100CLI - 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 textSuitable 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 toFargateandLambda -
Aims to simplify savings planning on
EC2instances -
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
VPCspans allAZs in theRegion. -
CLI
-
aws ec2 create-default-vpccreate a default
VPC -
aws ec2 create-default-subnet --availability-zone <AZ>create a default
subnet
-
-
Recipes
-
Calculate subnet
CIDRblock based onVPCCIDRblockUse
ipcalc
-
-
References
VPC - Subnet
-
A
subnetalways belongs to oneVPConce created. -
A
subnetis associated with only oneAZ. -
Subnet CIDR blockmust be a subset of theVPC CIDR block. -
172.16.0.0/21means the first21bits are used to identify network (subnet), the rest of bits are used identify hosts. In this case,21bits are used for network identification, while32 - 21 = 11bits are used for host identification. Therefore, when assigning IP addresses, the first21bits are fixed, while the rest bits will increment until all allocated. -
public
subnetis asubnetthat's associated with aroute tablethat has a route to aninternet gateway. -
You can make a default
subnetinto a privatesubnetby removing the route from the destination0.0.0.0/0to theinternet gateway. -
Resources
VPC - Route Table
- A
route tablealways belongs to oneVPConce created. - A
subnetcan only be associated with oneroute tableat a time, but you can associate multiplesubnets with the sameroute table. - Each
subnetin yourVPCmust be associated with aroute table, which controls the routing for thesubnet(subnet route table). - If not explicitly specified, the
subnetis implicitly associated with themain route table. - Your
VPChas an implicitrouter table, and you useroute tablesto control where network traffic is directed. - If your
route tablehas 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 IPaddress is released. When you start it again, a newpublic IPaddress 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 addressis free of charge when allocated to runningEC2instances, while charge applies when they are reserved but not in use.
VPC - Network ACL
-
One
Network ACLalways belongs to oneVPConce created. -
Operates at the
subnetlevel, able to be associated with multiplesubnets within the sameVPC, operating like filters, thereforestateless. -
Black / white list
-
Return traffic must be explicitly allowed by rules
-
Rules evaluation order
- By
Rule numberin ascending order - First matched first served like a if/else block
- By
VPC - Security Group
- Operates at the
instancelevel, therefore only in effect when associated withinstance(s), thereforestateful. - By default, a
security groupincludes anoutbound rulethat allows alloutboundtraffic. White list only, you can specify allow rules, but not deny rules.- Return traffic is automatically allowed, regardless of
InboundorOutbound Inboundrules only specifysource IP, whileOutboundrules only specifydestination IP.- All rules are evaluated before a decision is made.
At most 5 Security Groupcan be associated with aninstance, and union of all rules from the all associatedSecurity Groupwould be applied to theinstance.- When you specify a
security groupas the source for an inbound or outbound rule, traffic is allowed from the network interfaces that are associated with the sourcesecurity groupfor 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 IPorElastic IP addresses). Adding asecurity groupas a source does not add rules from the sourcesecurity group. Default security groupcannot be deleted.By default, asecurity groupincludesan 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 22VPC - Security Group - Create a Security Group in the given VPC
aws ec2 create-security-group \
--group-name $group_name \
--description $description \
--vpc-id $vpc_idVPC - 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 allowedVPC - ENI (Elastic network interface)
AWS Docs - ENI (Elastic network interface) (opens in a new tab)
- Once created,
ENIs are specific to asubnet, but anElastic IPcan be disassociated from anENIand available again. ENIcan be detached from anEC2 instance, and attached to another instance.- The
primary ENIcannot be detached from anEC2 instance.
VPC Connection Options
VPC - Internet Gateway
AWS Docs - Internet Gateway (opens in a new tab)
- Only one
Internet Gatewaycan beattachedto oneVPCat a time. - Instances must have
public IPs. - Attaching an
Internet Gatewayto aVPCallowsinstanceswithpublic IPsto access the internet.
VPC - Egress-only Internet Gateway
AWS Docs - Egress-only Internet Gateway (opens in a new tab)
-
IPv6- An
egress-only internet gatewayis for use withIPv6traffic only. IPv6addresses are globally unique, and are therefore public by default.
- An
-
IPv4- To enable
outbound-onlyinternet communication overIPv4, use aNAT gatewayinstead.
- To enable
VPC - NAT Gateway
NAT Gateway (opens in a new tab)
- Fully managed, highly available
EC2instance NAT Gatewayallows privatesubnetto access theinternet,NAT Gatewaymust have anEIP.NAT Gatewaytraffic must be routed toInternet Gatewayin theroute table.- It only works one way. The
internetcannot get through yourNATto your private resources unless you explicitly allow it. EIPcannot be detached.- Bandwidth up to
45 Gbps - Cannot be associated with a
Security Group - Cannot function as a
Bastionhost
VPC - NAT Instance
- Self managed, but with more flexibility and customization
- An
EC2instance configured to performNAT EIPcan be detached.- Can be associated with a
Security Group - Can function as a
Bastionhost
VPC - VPC endpoint
-
A
VPC endpointenables you to privately connect yourVPCto supportedAWSservices andVPC endpointservices powered byAWS PrivateLink(opens in a new tab) without requiring aninternet gateway,NAT device,VPN connection, orAWS Direct Connect connection. -
VPC endpointtypesInterface endpointGateway Load Balancer endpointGateway endpoint
-
Key points
-
Pros
- Secure and private connection
- No internet needed
-
Cons
- Not all services are supported
- Not all
Regionsare supported - Cross region not supported
-
VPC - Interface endpoint
- An
interface endpointis anENIwith a private IP address from the IP address range of yoursubnetthat serves as an entry point for traffic destined to a supported service. interface endpointsare powered byAWS PrivateLink, which bills you for each hour that yourVPC endpointremains provisioned in eachAZ, irrespective of the state of its association with the service.
VPC - Gateway endpoint
- A
gateway endpointis a gateway that you specify as a target for a route in yourroute tablefor traffic destined to a supportedAWSservice. - Doesn't use
PrivateLink, therefore no hourly charge. - Only work in the same
Region - Only
S3andDynamoDBare supported Gateway endpointsdo not allow access from on-premises networks, frompeered VPCsin otherRegions, or through a transit gateway.
VPC peering
AWS Docs - VPC peering (opens in a new tab)
- A
VPC peeringconnection is a networking connection between twoVPCsthat enables you to route traffic between them using privateIPv4addresses orIPv6addresses. Instances in eitherVPCcan communicate with each other as if they are within the same network. You can create aVPCpeering connection between your ownVPCs, or with aVPCin another AWS account. TheVPCscan be in differentRegions(also known as aninter-Region VPC peering connection).
EC2
AWS Docs - EC2 (opens in a new tab)
-
Instance-
Each
Linux instancelaunches with adefault Linux system user account. Log in asdefault userto administrate theinstance, whiledefault useris not aroot user, it has permissions to install additional software. -
To get password of
default administratoron aWindows instance, you have to decrypt it with theEC2 instance key pair private key. -
EC2 metadata serviceis only accessible from theinstancefor query ofmeta information, such asIAM Rolename but notIAM policy. -
User data- Scripts entered as
user dataare executed as the root user. - By default,
user datascripts and cloud-init directives run only during the boot cycle when you first launch an instance.
- Scripts entered as
-
AMIisRegionspecific.AMIcan’t be changed for an existing instance.
-
Root volume(opens in a new tab)- The
root volumecontains theimageused to boot the instance. - Each instance has a single
root volume. Instance storebacked orEBSbacked
- The
-
Use
Security Token Service (STS)to decodeencoded authorization message
-
-
Instancepurchasing options-
On-Demand -
Reserved Instance(opens in a new tab)-
When you purchase a
Reserved Instance, you determine the scope of theReserved Instanceto be eitherregionalorzonal. -
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 InstancesorReserved Instancesfrom other sellers. -
Provide a capacity reservation when used in a specific
AZ, applicable toEC2,RDS,RedshiftandElastiCacheStandard- 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
RegionalZonalAZ 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 InstanceCapacity 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
EC2capacity in theAWScloud for stateless, fault-tolerant workload -
Spot Instance interruption(opens in a new tab)Spot Instance interruption is when
EC2reclaims aSpot Instance. -
Spot Fleet(opens in a new tab)A
Spot Fleetis a collection, or fleet, ofSpot Instances, and optionallyOn-Demand Instancesto meet the target capacity that you specified in theSpot Fleetrequest.
-
-
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
SSHintoEC2instances
- For
-
Troubleshoot
-
Error connecting to your instance:
Connection timed outVerify there is a
Security Groupinbound rulethat 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) -
ELBcan be enabled within a singleAZor across multipleAZto 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
WebSocketandHTTP/2 -
Register targets in
target groupsand route traffic totarget groups. -
Cross-zone load balancingis always enabled. -
Access logscapture detailed information about requests sent to theALB. -
ALBexposes a staticDNSfor access. -
Listeners-
A
listeneris a process that checks for connection requests, using theprotocolandportthat you configure. Therulesthat you define for alistenerdetermine how theload balancerroutes 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
ALBto 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 balancingis by default disabled.- Target type
EC2 InstancesIP addresses
- Operate at
-
Classic Load Balancer- Only for
EC2 Instances CLBexposes a staticDNSfor access.- A
CLBwithHTTPorHTTPSlisteners might route more traffic to higher-capacity instance types.
- Only for
-
-
Target group-
Target type
-
One to many
EC2 Instances- Supports load balancing to
EC2instances within a specificVPC. - Facilitates the use of
EC2 Auto Scalingto manage and scale yourEC2capacity.
- Supports load balancing to
-
One to many
IP addresses- Supports load balancing to
VPCand on-premises resources. - Facilitates routing to multiple
IP addressesandnetwork interfaceson the same instance. - Offers flexibility with microservice based architectures, simplifying inter-application communication.
- Supports
IPv6targets, enabling end-to-endIPv6communication, andIPv4-to-IPv6NAT.
- Supports load balancing to
-
Single
Lambdafunction- Facilitates routing to a single
Lambdafunction. - Accessible to
ALBonly.
- Facilitates routing to a single
-
Application Load Balancer- Offers the flexibility for a
NLBto accept and routeTCPrequests within a specificVPC. - Facilitates using static
IPaddresses andPrivateLinkwith 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 tableDescribe 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 tableDescribe 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 tableAssociate a Security Group with the given Load Balancer
aws elbv2 set-security-groups \
--load-balancer-arn $load_balancer_arn \
--security-groups $security_group_idShow 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
doneEC2 - Auto Scaling
AWS Docs - Auto Scaling (opens in a new tab)
Auto Scaling groupcan span across multipleAZswithin aRegion, but not across multipleRegions.Auto Scalingworks with all 3 load balancers.CloudWatch Alarmscan be used to triggerAuto Scalingactions.
EC2 - Launch Template
AWS Docs - Launch Template (opens in a new tab)
-
Improvements over
Launch Configuration-
Supports versioning, while
Launch Configurationis immutable -
Supports multiple instance types and purchase options
-
More
EC2options- 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 groupstarts by launching enoughEC2instances to meet itsminimum capacity(or itsdesired capacity, if specified). - The
minimumandmaximum capacityare required to create anAuto Scaling group. Desired capacity(either by manual scaling or automatic scaling) must fall between theminimumandmaximum capacity.
EC2 - Scaling policy
AWS Docs - Scaling policy (opens in a new tab)
-
A
scaling policyinstructsAuto Scalingto track a specificCloudWatch metric, and it defines what action to take when the associatedCloudWatch alarmis inALARM. The metrics that are used to trigger an alarm are an aggregation of metrics coming from all of theinstancesin theAuto Scaling group. -
Target tracking scaling- The
scaling policyadds or removes capacity as required to keep themetricat, or close to, the specifiedtarget value. - Triggered by an automatically created and managed
CloudWatch AlarmbyEC2 Auto Scaling, which users shouldn't modify. - You don't need to specify scaling action.
- eg: Configure a
target tracking scalingpolicy to keep the average aggregateCPU utilizationof yourAuto Scaling groupat40 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 cooldownhelps you prevent yourAuto Scaling groupfrom 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 monitoringis enabled when you create alaunch templateor when you use theAWS Management Consoleto create alaunch configuration. - By default,
detailed monitoringis enabled when you create alaunch configurationusing theAWS CLIor anSDK.
- By default,
- Health check (opens in a new tab)
Auto Scalingcan determine the health status of aninstanceusing one or more of the following:EC2Status ChecksELBHealth Checks- Custom Health Checks
- The default health checks for an
Auto Scalinggroup areEC2status checks only.
EBS (Elastic Block Store)
-
Can only be attached to another
instancewithin the sameAZ -
Backup and restore
snapshotcan be used to share data withinstancesin anotherAZ. -
Usually one volume can only be attached to one
instanceat a time (Multi-Attachis not common) -
You can use block-level storage only in combination with an
EC2 instancewhere theOSis running -
After you attach an
EBSvolume 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
volumesare raw block devices without afile system. Volumesthat were created fromsnapshotslikely have afile systemon them already.
- New
-
Amazon Data Lifecycle Manager- Automate the creation, retention, and deletion of
EBS snapshotsandEBS-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
snapshotis created immediately, but the status of thesnapshotis pending until thesnapshotis complete -
Stored in
S3 -
Be aware of the performance penalty when initializing
volumesfromsnapshots -
Fast Snapshot Restore (opens in a new tab)
enables you to create a volume from a
snapshotthat 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)gp2volumes can support a sustained load of up to3000IOPS for up to 30 minutes at a time.- IOPS/Volume
< 34 GiB:100IOPS>= 34 GiB & <= 5333 GiB: incremental3IOPS / GiB> 5333 GiB:16,000IOPS
-
Provisioned IOPS SSD (opens in a new tab) (
io1,io2,io2 Block Express)-
Max IOPS/Volume:
64,000 -
The maximum ratio of
provisioned IOPStorequested volume size(inGiB) is50:1forio1volumes, and500:1forio2volumes. -
io2 Block Express Volumes (opens in a new tab)
- Up to 4x higher throughput, IOPS, and capacity than
io2volumes, 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), andETLworkloads
-
-
Performance Characteristics
Throughput = Size per IO Operation * IOPSSize per IO Operation- the amount of data written/read in a single IO request.
- data / request
EBSmerges smaller, sequential I/O operations that are32 KiBor over to form a single I/O of256 KiBbefore processing.EBSsplits I/O operations larger than the maximum256 KiBinto 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
EC2instances accessEBSvolumes over network connections.EBSvolumes can be accessed using dedicated networks (available onEBS-optimized instances) and shared networks (nonEBS-optimized instances).
-
Encryption
- You encrypt
EBSvolumes by enabling encryption, either usingencryption by defaultor by enabling encryption when you create a volume that you want to encrypt. EBSencryption usesKMSCMKwhen creating encrypted volumes and snapshots.- Encryption operations occur on the servers that host
EC2instances, ensuring the security of bothdata-at-restanddata-in-transitbetween an instance and its attachedEBSstorage. Encryption by defaultis 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
volumescannot be unencrypted.
SnapshotsSnapshotscreated from an encryptedvolumeare always encrypted.- Encrypted
snapshotscannot be unencrypted. - Unencrypted
snapshotscan only be encrypted when beingcopied.
- Encrypted data include:
- Data at rest inside the
volume - Data in transit between the
volumeand theinstance - All
snapshotscreated from thevolume - All
volumescreated from thosesnapshots
- Data at rest inside the
- You encrypt
EFS (Elastic File System)
Region-specific- Traditional filesystem hierarchy
- The main differences between
EBSandEFSis thatEBSis only accessible from a singleEC2instance in your particularRegion, whileEFSallows you to mount the file system across multipleRegionsandinstances.
Elastic Beanstalk
-
PaaSbased onEC2, usingCloudFormationunder the hood. -
ApplicationApplication 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 policyto your applications.
- Removing
applicationwill also trigger removal of all associated resources such asenvironment,EC2Instance, etc.
-
Environment- You can run either a
web serverenvironment or aworkerenvironment. - Use
Validate VPC Settingsbutton inEnvironmenttab to troubleshoot network. - If you associate an existing
RDSinstance to an existingEBenvironment, theRDSinstance must be launched from asnapshot. Environmenttype can beLoad BalancedorSingle Instance.- When you terminate an
environment, you can save its configuration to recreate it later. HTTPS- The simplest way to use
HTTPSwith anElastic Beanstalkenvironment 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
YAMLorJSON-formatted documents with a.configfile 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
-
-
.elasticbeanstalkdirectory-
Saved configurationSaved configurationsareYAMLformatted templates that define an environment's platform version, tier, configuration option settings, and tags.Saved configurationsare located under.elasticbeanstalk > saved_configsin project directory.
-
-
Config files in the project directory
-
env.yamlYou can include a
YAMLformatted 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.yamlin your source bundle to add jobs to yourworker environment's queue automatically at a regular interval.
-
-
Elastic BeanstalksupportsCloudFormationfunctions (Ref,Fn::GetAtt,Fn::Join), and oneElastic Beanstalk-specific function,Fn::GetOptionSetting.
-
-
-
Docker- Single-container
- Multi-container
-
Custom platform- A
custom platformlets you develop an entire newplatformfrom scratch, customizing the operating system, additional software, and scripts thatElastic Beanstalkruns onplatforminstances. - To create a
custom platform, you build anAMIfrom 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 statusGets environment information and status
-
eb printenvShows the environment variables
-
eb listLists all environments
-
eb setenv <env-variable-value-pairs>Sets environment variables
eg:
eb setenv HeapSize=256m Site_Url=mysite.elasticbeanstalk.com -
eb sshOpens 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-onceDeploy the new version to all instances simultaneously.
-
RollingUpdates 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 batchThe 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 Beanstalkterminates the additional batch of instances.
-
-
Deploying to new instances
-
ImmutableInstances 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 Beanstalklaunches a full set of new instances just like during animmutabledeployment. 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 Beanstalkforwards all traffic to them and terminates the old ones.
-
-
Blue/Greendeployment (opens in a new tab)A new
environmentwill be created for thenew version(Green) independent of thecurrent version(Blue). When theGreenenvironmentis ready, you can swap theCNAMEsof theenvironmentsto redirect traffic to the newer runningenvironment.Blue/greendeployments require that yourenvironmentruns 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, updatePORTenvironment variable. - From
Management Console, the application to be uploaded must be an executableJARfile containing all the compiled bytecode, packaged in aZIParchive.
- Default port
CodeCommit
-
Regionspecific -
No public access
-
Authentication
-
SSHDedicated
SSH key pairof currentuserforCodeCommitonly -
HTTPSDedicated
HTTPS Git credentialsof currentuserforCodeCommitonly -
MFA
-
-
Authorization
-
IAMYou must have an
CodeCommitmanaged policy attached to yourIAMuser, belong to aCodeStarproject team, or have the equivalent permissions.
-
-
Cross-Account accessto a different account- Create a
policyfor access to the repository - Attach this
policyto arolein the sameaccount - Allow other
usersto 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
SNStopicAWS Chatbot(Slack)
- Events that trigger notifications (opens in a new tab) (
-
TriggersTriggersdo not useCloudWatch Eventsrules 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 branchCreate branch or tagDelete branch or tag
- Target
SNSLambda
CodeBuild
-
When setting up
CodeBuildprojects to accessVPC, choose privatesubnetsonly. -
Need access to
S3for code source, therefore 2 approachNAT Gateway(additional charge)S3Gateway Endpoint
-
Caching Dependencies (opens in a new tab)
-
S3stores the cache in an
S3 bucketthat is available across multiple build hosts -
Localstores a cache locally on a build host that is available to that build host only
-
Docker layer cacheCaches existing
Dockerlayers so they can be reused. Requires privileged mode. -
Source cacheCaches
.gitmetadata so subsequent builds only pull the change in commits. -
Custom cacheCaches directories specified in the
buildspecfile.
-
-
CodeDeploy
-
Application Revision
- A
revisioncontains a version of the source filesCodeDeploywill deploy to your instances or scriptsCodeDeploywill run on your instances.
- A
-
- Configuration:
appspec.ymlmust be present in the root directory of the application revision archive. filessection (opens in a new tab)- The paths used in
sourceare relative to theappspec.ymlfile, which should be at the root of your revision.
- The paths used in
- Configuration:
-
Compute platforms
EC2/On-Premises- Requires installed and running
CodeDeployagent on instances - Requires an
IAMinstance profile (a Role) forEC2instances (opens in a new tab)
- Requires installed and running
ECSLambda
-
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
EC2noton-premisesinstances supportblue/greendeployment. -
All
LambdaandECSdeployments areblue/green. -
Deployment configurations
-
EC2-
One at a time
Routes traffic to one instance in the replacement environment at a time.
-
-
-
All at once
-
CanaryTraffic 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
-
CanaryTraffic is shifted in two increments,
10%in the first increment, and the remaining90%after5 / 10 / 15 / 30 minutes. -
LinearTraffic is shifted in equal increments (
10%) with a fixed interval (1 / 2 / 3 / 10 minutes).
-
-
-
-
-
Deployment Group- A
deployment groupcontains individuallytaggedinstances,EC2instances inEC2 Auto Scalinggroups, or both. EC2instances must havetagsto be added into adeployment group.
- A
-
CodeDeployagent-
The
CodeDeployagent is a software package that, when installed and configured on aninstance, makes it possible for thatinstanceto be used inCodeDeploydeployments. -
The
CodeDeployagent is required only if you deploy to anEC2/On-Premisescompute platform. -
Checking
CodeDeployagent service is installed and running (opens in a new tab)sudo service codedeploy-agent status -
Logs on
EC2Linux 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
-
-
CodeDeployrolls back deployments by redeploying a previously deployed revision of an application as a new deployment. -
CodeDeployfirst tries to remove from each participatinginstanceall 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
pipelineis kicked-off whenever a change in the configured pipeline source is detected.CodePipelinecurrently supports sourcing fromCodeCommit,GitHub,ECR, andS3. -
When using
CodeCommit,ECR, orS3as the source for a pipeline,CodePipelineuses aCloudWatch Eventto detect changes in the source and immediately kick off a pipeline. -
When using
GitHubas the source for a pipeline,CodePipelineuses awebhookto detect changes in a remote branch and kick off the pipeline. -
CodePipelinealso 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 approvalaction. If anSNStopicARNwas included in the configuration of the action, a notification is published to theSNStopic, 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
Dockerto anECRregistry withget-login-password(opens in a new tab), run theaws ecr get-login-passwordcommand. (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.comDescribe repositories
aws ecr describe-repositories \
--query 'sort_by(repositories,&repositoryName)[].{Repo:repositoryName,URI:repositoryUri}' \
--output tableDescribe 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 tableFind 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 tableFind 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 tableECS
-
Container Instance- If you terminate a
container instancein theRUNNINGstate, thatcontainer instanceis automatically removed, or deregistered, from the cluster. However, if you terminate acontainer instancein theSTOPPEDstate, thatcontainer instanceisn't automatically removed from the cluster.
- If you terminate a
-
ECS Container Agent (opens in a new tab)
-
ECS_ENABLE_TASK_IAM_ROLEWhether
IAMrolesfortasksshould be enabled on thecontainer instancefortaskcontainers with the bridge or default network modes.
-
-
EC2Launch Type-
An
ECSCluster is a logical group ofEC2instances, also calledcontainer instance. -
Each
container instancehas anECScontainer agent(aDocker container) installed. -
Container instancecan only useAmazon Linux AMI -
ECScontainer agentregisters thecontainer instanceto the cluster. -
ECScontainer agentconfiguration/etc/ecs/ecs.config
-
Load balancing
-
ALBandNLBsupportsdynamic host port mapping(opens in a new tab), allowing you to have multipletasksfrom a single service on the samecontainer instance. -
To enable
dynamic host port mapping, host port must be set to0oremptyintask definition. -
CLBdoes not allow you to run multiple copies of ataskon the sameinstancebecause the ports conflict.
-
-
Task definition(opens in a new tab)- A
taskis similar to apodinKubernetes. - Container definitions (opens in a new tab)
- Define one or multiple containers
- Standard parameters:
Name,Image,Memory,Port Mappings
- Every
containerin atask definitionmust land on the samecontainer instance. - Need to specify resources needed
- Need to specify configuration specific to the
task - Need to specify the
IAMrole that yourtaskshould use
- A
-
Task placement (opens in a new tab)
-
-
binpackTasksare 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. -
randomRandomplaces tasks on instances at random. This still honors the otherconstraintsthat you specified, implicitly or explicitly. Specifically, it still makes sure thattasksare scheduled on instances with enough resources to run them. -
spreadTasks are placed evenly based on the specified value.
-
-
Constraint(opens in a new tab)-
distinctInstancePlace each task on a different container instance.
-
memberOfPlace tasks on container instances that satisfy an
Cluster queryexpression.
-
-
Cluster query language (opens in a new tab)
Cluster queriesare expressions for targeting container instances, which can be used intask placement memberOf constraint.
-
-
-
FargateLaunch Type- Fully managed
- Serverless
-
IAM-
Service-Linked Role (for
ECS) (opens in a new tab)- Granting
ECSthe permissions it requires to call otherAWSservices 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
taskexecution role grants theECScontainer andFargateagents permission to makeAWSAPIcalls on your behalf. - Use case
-
ECSContainer InstanceIAM Role(forcontainer instance) (opens in a new tab)-
Container instancesthat run theECScontaineragentrequire anIAMpolicyandrolefor the service to know that theagentbelongs to you. -
Containersthat are running on yourcontainer instanceshave access to all of thepermissionsthat are supplied to thecontainer instancerole throughinstance metadata. -
Use case
- Register a
containerinto a cluster
- Register a
-
-
IAM RoleforTasks(forcontainersin atask) (opens in a new tab)- an
IAM rolethat can be used by thecontainersin 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 typecan only be specified at the time of manually executing aLambdafunction. ThisLambdafunction execution is calledon-demand invocation. -
InvocationTypeparameter-
RequestReponseExecute synchronously
-
EventExecute asynchronously
-
DryRunTest 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)CognitoLexAlexaAPI GatewayCloudFront(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
S3SNSSESCloudFormationCloudWatch LogsCloudWatch EventsCodeCommitAWS Config
-
Lambdaadds 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 retentionand message loss would happen if function is overwhelmed. -
For higher throughput, consider using
SQSorKinesisandLambdaevent source mapping. -
- Either a
SNStopic or aSQSqueue, 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
-
Destinationsforasynchronous invocation(opens in a new tab)-
Types
SQS– A standardSQSqueueSNS– ASNStopicLambda– ALambdafunctionEventBridge– AnEventBridgeevent bus
-
You can configure condition of the destination to be
on successoron failure.
-
Lambda - event source mapping
Event source mapping (poll-based) (opens in a new tab)
-
A
Lambdaintegration setup for poll-based event sources (with data in potentially large volume) such asqueuesandstreams. -
Lambdapulls records from the data stream of event sources and invokes your function synchronously with an event that contains stream records.Lambdareads 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
Lambdafunctions directly -
Event source mappingsthat read from astreamare limited by the number ofshardsin the stream. -
Services
SQSDynamoDB StreamsKinesisMQMSK (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 functionto access otherAWSresources in your account.
- Assigned to
-
Invocation permissions- Assigned to
event source - Enable the
event sourceto communicate with yourLambdafunction.
- Assigned to
Lambda - runtime
Custom runtime (opens in a new tab)
-
You can implement a
Lambdacustom runtimein any programming language. -
A
runtimeis aprogramthat runs aLambdafunction's handler method when the function is invoked. You can include aruntimein your function'sdeployment packagein the form of an executable file namedbootstrap. -
A
runtimeis responsible for running the function's setup code, reading the handler name from an environment variable, and reading invocation events from theLambdaruntimeAPI. Theruntimepasses the event data to the function handler, and posts the response from the handler back toLambda. -
The
runtimecan be included in your function'sdeployment package, or in alayer. -
Scripting language runtime such as
Node.jsandPythonruntime 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 InitRuns the function’s initialization code (the code outside the main handler)
-
-
-
Invoke -
Shutdown
Lambda - function deployment
-
Lambdafunction's code consists of scripts or compiled programs and their dependencies. -
Deployment packagesize 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
Lambdafunction that you create and include in your package. -
-
Async handlers
- If your code performs an asynchronous task, return a promise or
awaitthe 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 MBto3008 MBin64-MBincrements - You can only directly configure the memory for your function, and
LambdaallocatesCPUpower in proportion to the amount of memory configured.
- From
-
Timeout
- Default is
3 seconds, and max is15 minutes (900 seconds). AWScharges based on execution time in100-ms increments.
- Default is
-
Network
- Network configuration
defaultVPC
- A
Lambdafunction in yourVPChas no internet access. - Deploying a
Lambdafunction in a publicsubnetdoesn't give it internet access or a publicIP. - Deploying a
Lambdafunction in a privatesubnetgives it internet access if you have aNAT Gateway / Instance. - Use
VPC endpointsto privately accessAWSservices 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
Regionis set with1000concurrent execution as a maximum to provide you1000concurrent functions to execute. You can open a support ticket withAWSto request an increase in your account level concurrency limit. -
Lambdarequires at least100unreserved concurrent executionsper account. -
Concurrency = (average requests per second) * (average request duration in seconds) -
Reserved concurrencyApplies to the entire
function, including allversionsandaliases -
Provisioned concurrency(opens in a new tab)- To enable a function to scale without fluctuations in latency.
Provisioned concurrencycannot exceedsreserved concurrency.Provisioned concurrencysimply initializes the assigned capactity upfront to avoid a cold-start, hence without noticeable latency.
-
Parallelization Factor(opens in a new tab)- For
streamprocessing (event source mapping),oneLambdafunction invocation processesoneshardat a time, namelyParallelization Factoris1. Parallelization Factorcan be set to increase concurrentLambdainvocations for eachshard, which by default is1.
- For
-
-
-
Each
Lambdafunctionversionhas a uniqueARN. After you publish aversion, it is immutable, so you cannot change it. -
A function
versionincludes:- function code and all associated dependencies
Lambda runtimethat invokes the function- All of the function settings, including the
environment variables - A unique
ARNto identify the specificversionof the function
-
-
-
An
aliasis a pointer to aversion, and therefore it also has a uniqueARN. Assign analiasto a particularversionand use thataliasin the application to avoid updating all references to the oldversion. -
An
aliascannot point to$LATEST. -
Weighted alias- An
aliasallows you to shift traffic between 2versionsbased on specified weights (%).
- An
-
-
- A
layeris a.zip file archivethat 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
5layersat a time. The total unzipped size of the function and alllayerscan't exceed the unzipped deployment package size limit of250 MB. Layersare extracted to the/optdirectory in the function execution environment. Eachruntimelooks 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_IDX-Raytracing header -
AWS_XRAY_CONTEXT_MISSING:RUNTIME_ERROR(default),LOG_ERRORLambdasets this toLOG_ERRORto avoid throwing runtime errors from theX-RaySDK.
-
-
Lambda - monitoring
-
-
Invocationsthe number of requests billed
-
Durationthe 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
StandardorExpress(opens in a new tab), and cannot be changed once created. -
StandardWorkflow- Maximum execution time:
1 year - Priced per
state transition. Astate transitionis counted each time a step in your execution is completed.
- Maximum execution time:
-
ExpressWorkflow-
Maximum execution time:
5 minutes -
Priced by
the number of executionsyou run, their duration, and memory consumption. -
Types
- Synchronous
- Asynchronous
-
IAM
-
Global, not
Regionspecific -
-
Format:
arn:partition:service:region:account:resource -
PartitionPartitionidentifies the partition that the resource is in. You cannot delegate access between accounts in differentpartitions.- Supported partitions
aws-AWSRegionsaws-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
IAMrolesandpoliciesfrom 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
AWSservice
-
IAM - Access Analyzer
-
Helps identify the resources in your organization and accounts, such as
S3buckets orIAMroles, that are shared with an external entity, to find out unintended access to your resources and data. -
Preview Access (opens in a new tab)
CreateAccessPreviewListAccessPreviewFindings
-
Validate Policy
ValidatePolicy
-
Resources
IAM - Access Advisor
- Use
last accessed informationto 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 IDandSecret Access key) - Web (
Web Management Console)
- Programmatic (
IAM - Role
-
Similar to a
Userwith attachedPermissionspolicies -
Not uniquely identified, but a distinct identity with its own permissions
-
Temporarily effective for a designated timeframe
-
If an
IAMuserassumes aRole, only the policies of the assumedRoleare evaluated. Theuser's ownpolicieswouldn't be evaluated. -
Cannot be added to
IAMgroups -
Trust policyspecifies who can assume aRole. -
An
IAMroleis 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
principaland theresourceare in differentAWS accounts, anIAMadministrator in the trusted account must also grant theprincipal entity(userorrole) permission to access theresource. -
Trust policyto authorize the specified account to assume the role. Forrolesfrom a different account, thePrincipal ARNcontains 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 policyto authorize aRoleinAccount B
-
Account B
Identity-based policyto authorize aUserinAccount Bto access the resource inAccount A
-
-
-
Instance profile (opens in a new tab)
EC2uses aninstance profileas a container for anIAM role.- If you use the
AWS Management Consoleto create aroleforEC2, the console automatically creates aninstance profileand gives it the same name as therole. - An
instance profileis 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-
Policiesthat you attach to anAWSidentity, such as auser,groupof users, orrole. -
Control what
actionsanentitycan perform, whichresourcesthey can use, and theconditionsin which they can use theresources. -
AWS Managed PoliciesPoliciesthat are created and managed byAWSitself
-
Custom Managed PoliciesPoliciesthat are created and managed by you in yourAWSaccount
-
-
Resource-based policies-
Policiesthat you attach to a resource, specifying whichAPI actionsof theresourceare allowed. -
Different services have their unique
resource-based policies. -
Resource-based policiesareinline policiesand there are no managedresource-based policies. -
Trust policyis aresource-based policyforIAM 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 variablesas placeholders when you don't know the exact value in theResourceelement and in string comparisons in theConditionelement.
- 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 boundaryfor anIAMentity (userorrole) sets the maximumpermissionsthat the entity can have. - You can attach
permissions boundariesonly to auserorrole, not agroup.
- The
AWS Organizations (opens in a new tab)
-
Features
Centralized managementof all of yourAWS accountsConsolidated billingfor all member accountsHierarchical groupingof your accounts to meet your budgetary, security, or compliance needsService control policies(SCPs)Tag policiesAI services opt-out policiesBackup policies- Free to use
Service control policies (SCP) (opens in a new tab)
- Affect only the member
accountsin anOrganization SCPsoffer central control over the maximum available permissions for allaccountsin anOrganization.SCPsare similar toIAMpermission policies and use almost the same syntax. However, anSCPnever grants permissions. Instead,SCPsare JSON policies that specify the maximum permissions for the affected accounts.SCPcan 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
AWSaccount orIAMuser. The credentials consist of anaccess key ID, asecret access key, and asecurity token. - Using the temporary credentials that are returned from the call,
IAMusers can then make programmatic calls to API operations that requireMFAauthentication. - 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
AWSresources 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
AWSrequest.
STS - Cheatsheet
STS - Get Caller Identity
-
GetCallerIdentityreturns details about theIAMuser orrolewhose 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 (
GETorLIST) consistency forPUTsandDELETEsofobjects - Strong read consistency for
S3 Select,S3 Access Control Lists,S3 Object Tags, andobject metadata - Updates to a single
object keyare atomic, and there is no way to makeatomic updatesacrosskeys. - High availability by replicating data across multiple servers within
AWSdata centers. Bucketconfigurations have aneventual consistencymodel.- Wait for
15 minutesafter enablingversioningbefore issuing write operations (PUTorDELETE) onobjectsin thebucket. S3does not supportobject lockingfor concurrent writers.
- Strong read-after-write (
S3 - Bucket
S3lists allbuckets, butbucketis 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
S3are simply shared name prefix Bucketname must be globally unique, and cannbot be changed once created.Bucketnames can consist only of lowercase letters, numbers, dots (.), and hyphens (-).- To ensure
Bucketnames areDNS-friendly, it's preferable to avoiddotsin names. ObjectsinBucketare private by default.- There are no limits to the number of prefixes in a
bucket.
S3 - Bucket - Versioning
-
Bucketscan be in one of 3 statesUnversioned(default)Versioning-enabledVersioning-suspended
-
Once you enable
versioningon abucket, it can never return to theunversionedstate. You can, however,suspend versioningon thatbucket. -
If you have not enabled
versioning,S3sets the value of theversion IDtonull. -
Objectsstored in yourbucketbefore you set the versioning state have aversion IDofnull. -
SuspendThis suspends the creation of
objectversions for all operations but preserves any existingobjectversions.
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
objectsfrom being deleted or overwritten for a fixed amount of time or indefinitely. -
Object Lockworks only inversioned buckets, andretention periodsandlegal holdsapply to an individualobject version. -
Use
Object Lockto meet regulatory requirements that requireWORMstorage, or add an extra layer of protection against object changes and deletion. -
Retention mode
-
Compliance modeThe protected object version can't be
overwrittenordeletedbyany user, including theroot userin 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 modeYou protect objects against being deleted by
most users, but you can still grant some users permission to alter theretention settingsordelete the objectsif necessary. You can also usegovernance modeto testretention-periodsettings before creating acompliance-moderetention period.
-
S3 - Bucket - Replication
Replication (opens in a new tab)
-
Both source and destination
bucketsmust haveversioningenabled. -
Destination
bucketscan be in differentRegionsor within the sameRegionas the sourcebucket. -
New objects
- Replicate new objects as they are written to the
bucket - Use live replication such as
CRRorSRR CRRandSRRare implemented with the sameAPI, and differentiated by thedestinationbucketconfiguration.
- 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 documentmust be specified, anderror documentis optional.- If you create a folder structure in your
bucket, you must have anindex documentat each level. In each folder, theindex documentmust have the same name, for example,index.html. S3website endpoints do not supportHTTPS. UseCloudFrontin that case.- Access a website hosted in a
S3bucket with a custom domain- The
Bucketis configured as a static website. - Bucket name must match the domain name exactly.
- Add an
alias recordinRoute53to route traffic for the domain to theS3 Bucket
- The
S3 - Bucket - Event Notifications
S3 Event Notifications (opens in a new tab)
- Destination
LambdafunctionSNStopicSQSstandardqueue (FIFOqueue not supported)EventBridgeevent bus
- If two writes are made to a single
non-versionedobject 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
versioningon 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
dailyorweeklybasis, 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 bucketmust be in the same Region as thesource bucket. S3 inventorygives youa complete list of your objects. This list will be published to thedestination bucket, and can be given inParquet,ORCorCSVformats, therefore can be analyzed withAthena.
S3 - Bucket - Select
S3 Select (opens in a new tab)
- Use a subset of
SQLstatements to filter the contents ofS3objectsand retrieve just the subset of data that you need. - By using
S3 Selectto filter this data, you can reduce the amount of data thatS3transfers, which reduces the cost and latency to retrieve this data. S3 Selectworks onobjectsstored inCSV,JSON, orApache Parquetformat with compression ofGZIPorBZIP2.- You can only query one
objectat 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
CloudFrontnetwork to accelerate transfer between your client and the specifiedS3 bucket. - Not recommended for small files or close proximity to the
S3Region.
S3 - Bucket - Analytics
S3 Analytics (opens in a new tab)
- You use
storage class analysisto observe yourdata access patterns over timeto gather information to help you improve the lifecycle management of yourSTANDARD_IAstorage. - 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 datawithdifferent permissions. -
Traits
-
Access pointsarenamed network endpointsattached tobucketsthat you can use to performS3 objectoperations, such asGetObjectandPutObject. -
For
S3 object operations, you can use theaccess point ARNin place of abucket name. -
Each
access pointhas distinct permissions and network controls thatS3applies for any request that is made through thataccess point. -
You can only use
access pointsto perform operations onobjects. -
S3 operations compatible with
access pointsAccess point compatibility with S3 operations (opens in a new tab)
-
S3 - Bucket - Access Points - Object Lambda
S3 Object Lambda (opens in a new tab)
-
ETLwithLambdaforS3data retrieval API -
Uses
Lambdafunctions to automatically process the output of standardS3GET,LIST, orHEADrequests. -
An
Object Lambda Access Pointis based on an existingS3 Access Pointand is used to invoke aLambda functionto processS3objectson 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
-
S3only supportssymmetric CMKs, notasymmetric CMKs. -
Server-side Encryption (opens in a new tab)
-
Adding the
x-amz-server-side-encryptionheader to theHTTPrequest to demand server-side encryption. -
- Use
AWS managed CMKto generatedata keyfor encryption, user intervention not needed x-amz-server-side-encryption: AES256
- Use
-
-
Use a
CMKyou created inKMSto generatedata keyfor encryption, requiring permission forKMSaccess -
x-amz-server-side-encryption: aws:kms -
When you upload an object, you can specify the
AWS KMS CMKusing thex-amz-server-side-encryption-aws-kms-key-idheader. If the header is not present in the request,S3assumes 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)Multipartuploading 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 keyupon every encryption and decryption action -
Must use
HTTPS -
S3does not store the encryption key you provide. Instead, it stores a randomly saltedHMACvalue of the encryption key to validate future requests. -
x-amz-server-side-encryption-customer-algorithmmust be
AES256 -
x-amz-server-side-encryption-customer-keythe 256-bit, base64-encoded encryption key
-
x-amz-server-side-encryption-customer-key-MD5message 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
S3only saving your data. - You can use your
CMKstored locally orCMKstored 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 encryptionis like having lunch at home.SSE-S3is like ordering takeaway from your office.SSE-KMSis like having lunch at your company's onsite canteen.SSE-Cis like bringing your lunch from home to work.
-
-
S3 Batch Operations
S3 Batch Operations (opens in a new tab)
- Large-scale batch operations on
S3objects EBscale- Requires
S3 Inventoryto be enabled
- Large-scale batch operations on
-
Uploading
- When a file is over
100 MB,multipartupload 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 usemultipartupload. Partsize:5 MB to 5 GB. There is no size limit on the last part of yourmultipartupload.Objectsize:0 to 5 TB- To perform a
multipartupload with encryption using anAWS KMSkey, the requester must havekms:GenerateDataKeypermissions to initiate the upload, andkms:Decryptpermissions to upload object parts. The requester must havekms:Decryptpermissions 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
3500PUT/COPY/POST/DELETEand5500GET/HEADrequests 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
S3object without authentication and authorization. -
Generated programmatically
-
GETfor downloading andPUTfor uploading -
As a general rule,
AWSrecommends usingbucket policiesorIAM policiesfor access control.ACLsis a legacy access control mechanism that predatesIAM. -
S3stores access logs asobjectsin abucket.Athenasupports analysis ofS3 objectsand can be used to queryS3access 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 ACLs.
S3 - Security - ACL
Access Control List (opens in a new tab)
- Can define which
AWSaccounts or groups are granted access and the type of access. - Can manage permissions of
Objects.
S3 - Bucket - Permissions - CORS
- To configure your
bucketto allow cross-origin requests, you create aCORSconfiguration.
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 AccesstierObjects uploaded to
S3 Intelligent-Tieringare stored in theFrequent Accesstier. -
Infrequent AccesstierObjects not accessed for 30 consecutive days are automatically moved to the
Infrequent Accesstier. -
Archive Instant AccesstierObjects not accessed for 90 consecutive days are automatically moved to the
Archive Instant Accesstier.
-
-
Frequent Access,Infrequent Access, andArchive Instant Accesstiers have the same low-latency and high-throughput performance ofS3 Standard -
The
Infrequent Accesstier saves up to40%on storage costs -
The
Archive Instant Accesstier 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 KBwill not be monitored and will always be charged at theFrequent Accesstier 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
AZand 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 compressedCSVorJSONfiles -
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 costarchive 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 yearwithretrieval 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 yearwithretrieval 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
-
S3origins -
Custom origins (
EC2,ELB)-
Origin Protocol Policy (opens in a new tab)
HTTP OnlyHTTPS OnlyMatch Viewer
-
-
-
Cache Behaviour Settings
-
Viewer Protocol Policy (opens in a new tab)
HTTP and HTTPSRedirect HTTP to HTTPSHTTPS Only
-
-
-
Lambda@Edge(opens in a new tab)Lambdafunctions ofPythonandNode.jsruntime can be deployed atCloudFrontedge locationsLambda@Edgeallows you to pass each request through aLambdato change the behaviour of the response.- Authorization@Edge (opens in a new tab): You can use
Lambda@Edgeto help authenticate and authorize users for the premium pay-wall content on your website, filtering out unauthorized requests before they reach yourorigininfrastructure.
-
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
S3content by using anOrigin Access Identity, a specialCloudFrontuser, which the targetS3bucket can reference inbucket policy. Once set up, users can only access files throughCloudFront, not directly from theS3bucket.
- Restricting Access to
-
-
MediaStore
-
-
-
Serving private content (opens in a new tab)
-
To use
signed URLsorsigned cookies, you need asigner. Asigneris either a trusted key group (Recommended) that you create inCloudFront, or anAWSaccount that contains aCloudFrontkey pair (can only be created by root user). -
You cannot use either
signed URLsorsigned cookiesif originalURLcontainsExpires,Policy,Signature,Key-Pair-Idquery parameters. -
Signed URL(opens in a new tab)- Uses a
JSONpolicy statement (canned or custom) to specify the restrictions of thesigned URL - Use
signed URLswhen you want to restrict access to individual files. - Use
signed URLswhen your users are using a client that doesn't supportcookies.
- Uses a
-
Signed cookies(opens in a new tab)- Use
signed cookieswhen you want to provide access to multiple restricted files. - Use
signed cookieswhen you don't want to change your currentURLs.
- Use
-
-
Using HTTPS with CloudFront (opens in a new tab)
- Both connections between
viewersandCloudFront, and connections betweenCloudFrontandorigincan be encrypted by usingHTTPS. - You can't use a self-signed
SSLcertificate forHTTPScommunication betweenCloudFrontand yourorigin, and the certificate must be managed byACM. - You don't need to add an
SSLcertificate if you only requireHTTPSfor communication between theviewersandCloudFront(default certificate provided byCloudFront).
- Both connections between
-
Availability
Origin failover(opens in a new tab)- an
origin groupwith twoorigins: aprimaryand asecondary. If theprimary originis unavailable, or returns specificHTTPresponse status codes that indicate a failure,CloudFrontautomatically switches to thesecondary origin. - To set up
origin failover, you must have adistributionwith at least 2origins.
- an
RDS
AWS Docs - RDS (Relational Database Service) (opens in a new tab)
-
Authentication
IAMdatabase authentication (opens in a new tab)- Only works with
MySQLandPostgreSQL. - Instead of password, an
authentication tokenis generated byRDSwhen you connect to aDB instance. - Each
authentication tokenhas 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 instancethat only allows read-only connections; applications can connect to aread replicajust as they would to anyDB instance. -
Asynchronous replication to a
Read Replica -
Uses a different
DB connectionstring than the one used by themaster instanceTo 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 instancein a differentAZ -
In case of an infrastructure failure,
RDSperforms an automatic failover to the standby instance (or to aread replicain 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
failovermechanism automatically changes theDNSCNAMErecord of theDBinstance to point to thestandby instance. -
The
standby instancecannot be used as aread replica. -
Multi-AZ DB instance deployment1standby DB instance- failover support
no read trafficsupport
-
Multi-AZ DB cluster deployment3DB 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 instanceis created with a new endpoint (the oldDB instancecan be deleted if so desired). This is done to enable you to create multipleDB instancesfrom a specificDB snapshotor point in time. -
Automated backupsare limited to a singleRegionwhilemanual snapshotsandread replicasare supported across multipleRegions. -
Manual
snapshot- When you delete a
DB instance, you can create a final DBsnapshotupon deletion. - Manual
snapshotsare 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
instanceis deleted - Stored in
S3 - Storage of automated
snapshotsare free as long as the DBinstanceis running. If the DBinstanceis stopped, the storage of automatedsnapshotswould be charged as per standard pricing.
- Configurable retention period with
-
-
Encryption
-
Encrypting a
DB instance(opens in a new tab)RDSprovides at-rest data encryption, so all logs, backups, andsnapshotsare encrypted.RDSuses anAWSKMSCMKto encrypt these resources.- For
OracleorSQL Server,RDSalso supports encrypting aDB instancewithTDE(Transparent Data Encryption).TDEis aDB built-in featureand supports both in-transit and at-rest data encryption, but forSQL Server, onlyEnterprise EditionsupportsTDE.
-
Encrypting a connection to a
DB instance(opens in a new tab)- Use
SSL/TLSfrom 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)
RDSprovidesmetricsin real time for theOSthat yourDB instanceruns on.Enhanced Monitoringmetricsare stored in theCloudWatch Logsinstead of inCloudwatch Metrics.- After you have enabled
Enhanced Monitoringfor yourDB instance, you can view themetricsfor yourDB instanceusingCloudWatch Logs, with eachlog streamrepresenting a singleDB instancebeing monitored. CloudWatchgathersmetricsaboutCPU utilizationfrom thehypervisorfor aDB instance, andEnhanced Monitoringgathers itsmetricsfrom anagenton theinstance.
- Enhanced Monitoring (opens in a new tab)
RDS - Aurora
AWS Docs - Aurora (opens in a new tab)
- Serverless, fully managed
RDBMScompatible withMySQLandPostgreSQL. - Up to
5 timesthe throughput ofMySQLand up to3 timesthe throughput ofPostgreSQLwithout 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 poolandreuses connectionsin 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 tableList DB instances
aws rds describe-db-instances \
--query 'sort_by(DBInstances,&DBInstanceIdentifier)[].{InstanceID:DBInstanceIdentifier, InstanceARN:DBInstanceArn, Engine:Engine, Version:EngineVersion, Status:DBInstanceStatus}' \
--output tableDynamoDB
- Schemaless, you can only specify
keysupon creation of tables,non-key attributescan only be added as part of new records.
DynamoDB - Availability
Regionspecific- Data replicated among multiple
AZs in aRegion
DynamoDB - Table Class
-
Standard- Offers lower throughput costs than
DynamoDB Standard-IAand 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) costof a table using theDynamoDB Standardtable class, theDynamoDB Standard-IAtable 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 keyspace inDynamoDBis to expand the space. -
Random Sharding (opens in a new tab)
add
a random numberto the end of thepartition keyvalues. -
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 keyand asort keythat 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 tableacross all partitions. - The
main table's primary key attributes are always projected into an index. Up to 20GSI/ table (soft limit)- Can be created after table creation
RCUandWCUprovisioned independently ofmain table, and therefore aQueryoperation on aGSIconsumesRCUfrom theGSI, not themain table. When you change items in a table, theGSIon that table are also updated. These index updates consumeWCUfrom theGSI, not from themain table.- If the writes are throttled on the
GSI, the write activity on themain tablewill 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 aGSIdo not need to beunique.
DynamoDB - LSI
- An index with the same
Partition keybut a differentSort key Up to 5LSI/ table (hard limit)- Cannot be created after table creation
- Use the
WCUandRCUof the base table - No special throttling considerations
- Supports both
strongandeventualconsistent reads - A
LSIlets you query over a single partition, as specified by thepartition keyvalue in the query.
DynamoDB - Read Consistency
-
Read committedisolation level -
base tableStrongly consistent readEventually consistent read
-
LSIStrongly consistent readEventually consistent read
-
GSIEventually consistent read
-
DynamoDB streamsEventually consistent read
DynamoDB - Capacity
-
Throughput mode:
ProvisionedorOn-Demand -
Read Capacity Unit (RCU)1 RCU=1strongly consistent read/s or2eventually consistent read/s, for an item up to4 KBin 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=1write/s for an item up to1 KBin 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 capacityrebalances 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
Queryrequires thepartition keyvalue and returns all items with it. Optionally, you can provide asort keyattribute and use a comparison operator to refine the search results.- A
filter expressiondetermines which items within theQueryresults should be returned to you. This happens after the itmes are returned therefore doesn't improve performance. - A single
Queryoperation can retrieve a maximum of1 MBof data. Queryresults are always sorted by thesort keyvalue, by default in ascending order.
DynamoDB - Scan
- Reads every item in a table or a secondary index
- By default, a
Scanoperation 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), thescanstops and results are returned to the user as aLastEvaluatedKeyvalue to continue thescanin a subsequent operation. - a
Scanoperation reads an entirepage(by default,1 MB), you can reduce the impact of thescanoperation by setting a smallerpagesize. - Each
QueryorScanrequest that has a smallerpagesize uses fewer read operations and creates a "pause" between each request. ScanusesLimitparameter to set thepagesize for your request.Parallel Scan- The table size is
20 GBor larger. - The table's provisioned
RCUis not being fully used. - Default sequential
Scanoperations 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
Numberdata 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-8601format)
- 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
DynamoDBthat runs in as a cluster in yourVPC. - Should be provisioned in the same
VPCas theEC2instances 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 consistentreads 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 readmode-
Item Cache (opens in a new tab)
GetItemBatchGetItem
-
Query Cache (opens in a new tab)
QueryScan
-
-
The following
DAXAPI operations are consideredwrite-throughBatchWriteItemUpdateItemDeleteItemPutItem
-
Misc
ElastiCachecan be used with other DBs and applications, whileDAXis forDynamoDBonly.
DynamoDB - Transaction
- Supports transactions via the
TransactWriteItemsandTransactGetItemsAPI calls. Transactionslet 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 tablesyou can specify theRegionswhere you want the table to be available.DynamoDBperforms all of the necessary tasks to create identical tables in theseRegionsand propagate ongoing data changes to all of them. DynamoDB global tablesuse a “last writer wins” reconciliation between concurrent updates, and therefore doesn't supportoptimistic locking.
DynamoDB - Streams
-
Capture
item-level changesin your table, and push the changes to aDynamoDB stream. You then can access the change information through theDynamoDB Streams API. -
View type
-
Keys onlyOnly the key attributes of the modified item
-
New imageThe entire item, as it appears after it was modified
-
Old imageThe entire item, as it appeared before it was modified
-
New and old imageBoth the new and the old images of the item
-
-
Streamsdo not consumeRCUs. -
All data in
DynamoDB Streamsis subject to a24-hourlifetime.
DynamoDB - Conditional operations
-
Put,DeleteandUpdatecan be performed with conditions specified withConditional Expressions(opens in a new tab). -
The internal implementation of
optimistic lockingwithinDynamoDBMapperusesconditional updateandconditional deletesupport provided byDynamoDB. -
Optimistic Locking with Version Number (opens in a new tab)
- Use
@DynamoDBVersionAttributeannotation 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 counterwould not be appropriate where overcounting or undercounting can't be tolerated.
DynamoDB - Quota
- The
maximum item sizeis400 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 backupwithper-second granularityso 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 availabilityof 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
-
ElastiCacheis only accessible to resource operating within the sameVPCto 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.
-
TTLspecifies 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
DNSrecord types (opens in a new tab)-
A(Address) recordsAssociate a domain name or subdomain name with the
IPv4address of the corresponding resource -
AAAA(Address) recordsAssociate a domain name or subdomain name with the
IPv6address of the corresponding resource -
CAA
A
CAArecord specifies whichcertificate authorities(CAs) are allowed to issue certificates for a domain or subdomain. Creating aCAArecord helps to prevent the wrongCAsfrom issuing certificates for your domains. -
- Reroute traffic from one domain name (example.net) to another domain name (example.com)
- The
DNSprotocol does not allow you to create aCNAMErecord for the top node of aDNSnamespace (zone apex).
-
DSA
delegation signer(DS) record refers a zone key for a delegated subdomain zone. You might create aDSrecord when you establish a chain of trust when you configureDNSSECsigning. -
MX(Mail server) recordsRoute traffic to mail servers
-
NAPTRA
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
NSrecord identifies the name servers for the hosted zone. -
PTR
A
PTRrecord maps anIPaddress 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,
TXTis recommended instead. -
SRV
SRVrecords are used for accessing services, such as a service for email or communications. -
TXT
A
TXTrecord contains one or more strings that are enclosed in double quotation marks (").
-
-
Aliasrecords (opens in a new tab)- Unlike a
CNAMErecord, you can create analiasrecord at the top node of aDNSnamespace (zone apex). - To route domain traffic to an
ELB load balancer, useRoute 53to create analias recordthat points to your load balancer. - A
zone apexrecord is aDNSrecord at the root of aDNSzone, and thezone apexmust be anArecord.
- 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
Regionsand you want to route traffic to theregionthat provides the best latency. -
Multivalue answer routing policy
Use when you want
Route 53to respond toDNSqueries with up to eight healthy records selected at random. -
Weighted routing policy
Use to route traffic to multiple resources in specified proportions.
-
-
TTLDNSrecords cache has aTTL. AnyDNSupdate will not be visible untilTTLhas elapsed.TTLshould 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 Resolverautomatically answersDNSqueries for:-
Local
VPCdomain names forEC2instancese.g.
ec2-192-0-2-44.compute-1.amazonaws.com -
Records in
private hosted zonese.g.
acme.example.com -
For
public domain names,Route 53 Resolverperforms 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 logAPIactions with finer granularity, but requiring correspondingCloudTraillogging being enabled
- Events directly supported by
- Timing
-
Target
- A variety of
AWSservices
- A variety of
-
-
AWSservice events are free -
Custom events (
PutEventsactions) 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 anotherAWSaccount. - supports native
AWSevents as well as third-party partner events. - supports content-based filtering.
- supports input transformation.
- has built-in schema discovery capabilities.
CloudWatch Metrics
-
MetricsareRegionbased. -
Namespace
- A
namespaceis a container formetrics, andmetricsin differentnamespacesare isolated from each other, such asAWS/EC2 - AWS services that publish CloudWatch metrics (opens in a new tab)
- A
-
Dimension
- A
dimensionis a unique identifier ofmetrics, such asinstanceID. - Up to 10
dimensionspermetric, and eachdimensionis defined by a name and value pair.
- A
-
Custom Metrics (opens in a new tab)
- Can only be published to
CloudWatchusing theAWS CLIor anAPI. - Use
PutMetricDataAPI action programmatically
- Can only be published to
-
Metric Math (opens in a new tab)
- Enables you to query multiple
CloudWatch metricsand use math expressions to create new time series based on thesemetrics.
- Enables you to query multiple
-
Resolution
- Predefined
Metricsproduced byAWSservices arestandard resolution. - When you publish a
Custom Metric, you can define it as eitherstandard resolutionorhigh resolution. - Standard resolution:
1 minutegranularity - High resolution:
1 secondgranularity
- Predefined
-
-
CloudWatchAWS/EC2namespace (opens in a new tab)-
These metrics are collected by
CloudWatch Metricsunder namespaceAWS/EC2. 2 modes for metrics collection,basic monitoringordetailed monitoring.-
Basic MonitoringEC2sends metric data toCloudWatchin5-minuteperiods at no charge.
-
Detailed Monitoring-
EC2sends metric data toCloudWatchin1-minuteperiods for an additional charge. -
Enable
detailed monitoringusingAWS CLIaws 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
CWAgentinCloudWatch Metrics. CloudWatch Agentalso can collect logs.
- For metrics not available under namespace
-
-
List
AWSservices publishingCloudWatch Metrics(opens in a new tab)aws cloudwatch list-metrics [--namespace <namespace>] [--metric-name <metric-name>]
CloudWatch Alarms
-
Metric
-
An
Alarmwatches a singlemetricover a specified time period, and performs one or more specifiedactions, based on the value of themetricrelative to a threshold over time. -
A value of the metric is a data point.
-
PeriodforAWS Metricscannot be lower than 1 minute. -
Alarmon High ResolutionCustom MetricsPeriodof10 or 30 seconds(High ResolutionAlarm(opens in a new tab) with additional charge)Periodof1 minute(regularAlarmwith 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)
-
PeriodThe length of time in seconds to evaluate the metric or expression to create each individual
data pointfor analarm -
Evaluation PeriodsThe number of the most recent
periods, ordata points, to evaluate when determiningalarmstate. -
Data points to alarmDefine the number of
data pointswithin the evaluationperiodthat must be breaching to cause thealarmto go toALARMstate.
-
-
Action
- a notification sent to a
SNStopic Auto ScalingactionsEC2actions (only applicable toEC2 Per-Instance Metrics)
- a notification sent to a
-
States
-
ALARMThe
metricis within the defined threshold -
INSUFFICIENTThe
metricis beyond the defined threshold -
OKThe
alarmhas only just been configured, themetricis unavailable, or we do not have sufficient data for themetricto determine thealarmstate.
-
CloudWatch Logs
-
CloudWatchlogs never expire by default. -
Log data retention can be configured on
Log grouplevel. -
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
Regions, recording events in allRegions - Applies to one
Region, recording events in thatRegiononly Organizationtrail (opens in a new tab)- If you have created an
Organization, you can also create atrailthat will log all events for allAWSaccounts in thatOrganization. Organizationtrails can apply to allRegionsor oneRegion.Organizationtrails must be created in the management account.- Member accounts will be able to see the
Organizationtrail, but cannot modify or delete it. - By default, member accounts will not have access to the log files for the
Organizationtrail in theS3bucket.
- If you have created an
- Applies to all
- Events (opens in a new tab)
- Management events
- Data events (additional charges apply)
CloudTrail Insightsevents
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
JSONformat toORCformat
X-Ray
-
A distributed tracing solution, especially for apps built using a microservices architecture
-
Segment- At a minimum, a
segmentrecords thename,ID,start time,trace ID, andend timeof the request. - A
segmentdocument can be up to64 KBand contain a wholesegmentwithsubsegments, a fragment of asegmentthat indicates that a request is in progress, or a singlesubsegmentthat is sent separately. You can sendsegmentdocuments directly toX-Rayby using thePutTraceSegments API. - When you instrument your application with the
X-Ray SDK, theSDKgeneratessegmentdocuments for you. Instead of sendingsegmentdocuments directly toX-Ray, theSDKtransmits them over a localUDPport to theX-Ray daemon.
- At a minimum, a
-
Subsegment-
Subsegmentprovides more granular timing information and details about downstream calls that your app made to fulfill the original request. -
Subsegmentscan contain othersubsegments, so a customsubsegmentthat recordsmetadataabout an internal function call can contain other customsubsegmentsandsubsegmentsfor downstream calls. -
A
subsegmentrecords a downstream call from the point of view of the service that calls it. -
Field
namespace-awsforAWSSDKcalls;remotefor other downstream calls.
-
-
Service Graphis a flow chart visualization of average response for microservices and to visually pinpoint failure. -
Tracecollects allSegments generated by a single request so you can track the path of requests through multiple services.Trace IDinHTTPheader (Tracing header) is namedX-Amzn-Trace-Id.
-
Samplingis an algorithm that decides which requests should be traced. By default,X-Rayrecords the first request each second and5%of any additional requests. -
Annotations- Use
Annotations(opens in a new tab) to record information onSegments orSubsegments that you want indexed for search. Annotationssupport 3 data types:String,NumberandBoolean.- Keys must be alphanumeric in order to work with
filters. Underscore is allowed. Other symbols and whitespace are forbidden and ignored. X-Rayindexes up to50annotationspertrace.
- Use
-
Use
Metadatato record data you want to store in thetracebut don't need to use for searchingtraces. -
Daemon
-
X-Raydeamon gathers raw segment data, and relays it to theX-RayAPI -
The
daemonworks in conjunction with theX-Ray SDKsand must be running so that data sent by theSDKscan reach theX-Rayservice. -
By default listens on
UDP port 2000 -
-r, --role-arn: Assume the specifiedIAM roleto uploadsegments to a different account. -
ECScreate a
Dockerimage that runs theX-Raydaemon, upload it to aDockerimage repository, and then deploy it to yourECScluster.
-
-
Instrumentation (opens in a new tab)
- Automatic
- Manual
KMS
-
Multi-tenantkey store management service operated byAWS. -
KMScan use its ownhardware security modules(HSMs) or a customer managedCloudHSMkey store. -
Regionspecific, a key that is created in oneregioncan't be used in anotherregion -
KMScentrally stores and manages the encryption keys calledKMS Key, andKMS Keysare stored in plain text, by default issymmetric. -
Encrypt,DecryptandReEncryptAPIactions are designed to encrypt and decryptdata keys, as they useKMS Keyand can only encrypt up to4 KBdata. -
Data over
4 KBcan only be encrypted withEnvelope Encryptionusing adata key. -
Types of
KMS KeyDescription Customer-managed AWS-managed AWS-owned Key creation customer AWSon behalf of customerAWSKey usage Customer can control key usage through the KMSandIAMpolicycan be used only with specific AWSservices whereKMSis supportedimplicitly used by AWSto protect customer data; customer can't explicitly use itKey rotation manually configured by customer rotated automatically once a year rotated automatically by AWSwithout any explicit mention of the rotation scheduleKey deletion can be deleted can't be deleted can't be deleted User access controlled by the IAMpolicycontrolled by the IAMpolicycan't be accessed by users Key access policy managed by customer managed by AWSN/A -
Encryption options in
KMS-
AWS managed keys- Encryption Method (
AWSmanaged) - Keys Storage (
AWSmanaged) - Keys Management (
AWSmanaged)
- Encryption Method (
-
Customer managed keys- Encryption Method (Customer managed)
- Keys Storage (
AWSmanaged,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 keyfor client-side encryption, including a plaintext copy of thedata keyand a copy that is encrypted under aCMKthat you specify. -
To encrypt data outside of
KMS:- Use the
GenerateDataKeyoperation to get adata key. - Use the plaintext
data key(in thePlaintextfield of the response) to encrypt your data outside ofKMS(Using any 3rd party cryptography library) - Erase the plaintext
data keyfrom memory. - Store the encrypted
data key(in theCiphertextBlobfield of the response) with the encrypted data.
- Use the
-
To decrypt data outside of
KMS:- Use the
Decryptoperation to decrypt the encrypteddata key. The operation returns a plaintext copy of thedata key. - Use the plaintext
data keyto decrypt data outside ofKMS. - Erase the plaintext
data keyfrom 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
AWSservices that encrypt data on your behalf require a symmetricCMK. -
Symmetric key
- Encrypt / Decrypt
-
Asymetric key
Encrypt/DecryptSign/Verify- Doesn't support automatic key rotation
- The standard
asymmetric encryptionalgorithms thatKMSuses 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-accountaccess requires permission in thekey policyof theKMS keyand in anIAM policyin the external user's account.- Add a
key policy statementin thelocal account - Add
IAM policiesin theexternal account
- Add a
-
Cross-accountpermission is effective only for certainAPIoperations
CloudHSM
- AWS Docs - AWS CloudHSM (opens in a new tab)
Single-tenanthardware security module withcomplete control- Customer operated
- Can be used as a
custom key storeforKMS
AWS Config
- By default, the configuration recorder records all supported resources in the
RegionwhereAWS Configis running. AWS Config Rules(opens in a new tab)AWS Config Rulesrepresent your ideal configuration settings.AWS Configcontinuously tracks the configuration changes. Any resource violating arulewill be flagged as non-compliant.
- Costs
- You are charged service usage fees when
AWS Configstarts 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 Configusage 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)
Automationhelps you to build automated solutions to deploy, configure, and manageAWSresources 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,
CloudTrailcapturesParameter StoreAPIcalls. Parameter StoreusesKMS CMKs(opens in a new tab) to encrypt and decrypt the parameter values ofSecureStringparameters when you create or change them.- You can use the
AWSmanagedCMKthatParameter Storecreates 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 tableCloudFormation
-
-
Use a
JSONorYAMLfile calledTemplateto specify a declarative, static definition ofAWSservice stack. -
The
Templatefile must be uploaded toS3before being used. -
ParametersParameterType (opens in a new tab)StringNumberList<Number>CommaDelimitedList- AWS-Specific Parameter Types (opens in a new tab)
SSMParameter Types (opens in a new tab)
- You use the
Refintrinsic function to reference aParameter, andAWS CloudFormationuses theParameter's value to provision the stack. You can referenceParameterfrom theResourcesandOutputssections of the same template. Pseudo parametersPseudo parametersareParametersthat are predefined byCloudFormation.- Use them the same way as you would a
Parameter, as the argument for theReffunction. - Their names start with
AWS::such asAWS::Region.
-
Resources- The only mandatory section
-
Conditions- The optional
Conditionssection contains statements that define the circumstances under which entities are created or configured. - Other sections such as
ResourceandOutputcan reference the conditions defined inConditionsection. - Use
Condition function(opens in a new tab) to define conditions.
- The optional
-
Mappings- The optional
Mappingssection 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,
exporta stack's output values. Other stacks that are in the sameAWSaccount andRegioncan import the exported values. - To export a stack's output value, use the
Exportfield in theOutputsection of the stack's template. To import those values, use theFn::ImportValuefunction 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
Refreturns the value of the specifiedParameterorResource. - When you
Refthe logical ID of anotherResourcein your template,Refreturns what you could consider as a default attribute for that type ofResource. So usingReffor anEC2instance will return theinstance ID,RefanS3bucket, it will return thebucket name.
- The intrinsic function
Fn::GetAtt(opens in a new tab): TheFn::GetAttintrinsic function returns the value of an attribute from a resource in the template.Fn::FindInMap(opens in a new tab): The intrinsic functionFn::FindInMapreturns the value corresponding to keys in a two-level map that is declared in theMappingssection.Fn::ImportValue(opens in a new tab): The intrinsic functionFn::ImportValuereturns 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::Joinappends 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::Subsubstitutes variables in an input string with values that you specify.
-
Helper scripts (opens in a new tab)
CloudFormationprovidesPythonhelper scripts that you can use to install software and start services on anEC2instance that you create as part of your stack.
-
-
-
Change set (opens in a new tab)
Change setsallow you to preview how proposed changes to astackmight impact your running resources.- Similar to a
diffto thestack.
-
-
StackSetsextends the functionality ofstacksby enabling you to create, update, or deletestacksacross multiple accounts andregionswith 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
CloudFormationtemplate references. - Uploads local artifacts, such as source code for an
Lambdafunction or aSwaggerfile for anAPI Gateway REST API, to anS3bucket. Note it is the local artifacts being uploaded, not the template. - Returns a copy of your template, replacing references to local artifacts with the
S3location where the command uploaded the local artifacts.
- Packages the local artifacts (local paths) that your
-
Deploys the specified
CloudFormationtemplate 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 usesS3for message storage, supporting payload size up to2 GB. -
Number of messages (
up to 10) can be specified before retrieving. -
SQSmessage retention period ranges from1 minuteto14 days, by default4 days. -
Visibility timeout(opens in a new tab)- After a message is polled by a consumer, it becomes
invisibleto other consumers. - Message
visibility timeoutis the time for consumer to process the message, and it is30 secondsby default. - If not deleted within the
visibility timeoutwindow, the message will becomevisibleto other consumers again. ChangeMessageVisibilityaction can be used to prolongvisibility timeoutwindow.- If
visibility timeoutis too high, and consumer crashes meanwhile, reprocessing will take time. - If
visibility timeoutis 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.
-
SQSprovidesshort pollingandlong pollingto receive messages from a queue. By default, queues useshort polling.Long pollingdecreases the number of API calls made toSQSwhile increasing the efficiency and latency of your application.Long pollingis preferable toshort polling.Long pollingcan have a wait time from1to20second.
-
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 orderingviamessage grouping- Ordering across groups is not guaranteed.
- Messages that share a common
message group IDwill be in order within the group.
Deduplication- If you retry the
SendMessage actionwithin the5-minutededuplication interval,SQSdoesn't introduce any duplicates into the queue. - If a message with a particular
message deduplication IDis sent successfully, any messages sent with the samemessage deduplication IDare accepted successfully but aren't delivered during the5-minutededuplication interval. - If your application sends messages with unique message bodies, you can enable content-based deduplication.
- If you retry the
- Cannot subscribe to a
SNStopic
- Throughput:
-
-
Dead-letter queue (DLQ)- The
DLQof aFIFO queuemust also be aFIFO queue. - The
DLQof astandard queuemust also be astandard queue. - The
DLQand its corresponding queue must be in the same region and created by the same AWS account. Redrive policyRedrive policyspecifies the source queue, theDLQ, and the conditions under whichSQSmoves 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 countwill increment by1no matter the processing is successful or not, thereforeReceive countis essentially receive attempt count. - If a message
Receive countis more than the specifiedMaximum receives, the message will be sent to the specifiedDLQ. SQScounts a message you view in theAWS Management Consoleagainst 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
Topicallows multiple receivers of the message to subscribe dynamically for identical copies of the same notification. - By default,
SNSoffers10 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. TheTopics do not buffer messages. -
When several
SQSs act as a subscriber, a publisher sends a message to anSNStopic and it distributes this topic to manySQSqueues 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 poolsprovide temporaryAWScredentials for:- Unauthenticated guests
- Users who have been authenticated and received a token.
- Access to
AWSservices - Specific to your
AWSaccount
-
Cognito Sync(opens in a new tab)-
Synchronizing application data across devices
-
AppSyncis 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
Lambdafunction in response to important events inCognito.
-
API Gateway
-
REST API-
Stage variables- A
stageis a named reference to a deployment, which is a snapshot of theAPI. Stage variablesare name-value pairs that you can define as configuration attributes associated with a deployment stage of aREST API. They act likeenvironment variablesand can be used in yourAPIsetup andmapping templates.- A
stage variablecan be used anywhere in amapping template:${stageVariables.<variable_name>}
- A
-
Integrationtype (opens in a new tab)-
AWS(Lambdacustom integration)expose
AWSservice actions, must configure both theintegration requestandintegration response. -
AWS_PROXY(Lambdaproxy integration)-
This is the preferred integration type to call a
Lambdafunction throughAPI Gatewayand is not applicable to any otherAWSservice actions, includingLambdaactions other than the function-invoking action. -
In
Lambdaproxy integration (opens in a new tab),API Gatewayrequires the backendLambdafunction to return output according to the followingJSONformat.{ "isBase64Encoded": true|false, "statusCode": httpStatusCode, "headers": { "headerName": "headerValue", ... }, "multiValueHeaders": { "headerName": ["headerValue", "headerValue2", ...], ... }, "body": "..." }
-
-
HTTPexpose
HTTPendpoints in the backend, must configure both theintegration requestandintegration response. -
HTTP_PROXYexpose
HTTPendpoints in the backend, but you do not configure theintegration requestor the `integration response. -
MOCKAPI Gatewayreturn a response without sending the request further to the backend, useful for testing integration set up.
-
-
- Integration timeout:
50 millisecondsto29 secondsfor all integration types.
- Integration timeout:
-
API Gatewayresponses (opens in a new tab)-
502 Bad Gateway- Usually an incompatible output returned from a
Lambdaproxy 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 releasewith a pre-configured ratio. -
Mapping template
- A script expressed in
Velocity Template Language (VTL)and applied to the payload usingJSONPathexpressions to perform data transformation.
- A script expressed in
-
API cache
API Gatewaycaches responses from your endpoint for a specifiedTTLperiod, in seconds.- Default
TTLis 300 seconds, andTTL=0means caching is disabled. - Client can invalidate an
API Gatewaycache entry by specifyingCache-Control: max-age=0header, 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 keysassociated with yourusage planas client identifier.
-
Usage plan-
Uses
API keysto 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
rateis 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 Requestserror responses Burstessentially means the maxium number of requests that can be queued for processing. OnceBurstis 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,
Rateis the number of customers that are being served at that same time.Burstis 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:
-
Cognitouser pool (opens in a new tab)- Authentication:
Cognitouser pool - Authorization:
API Gatewaymethods - Seamless integration, no custom code needed
- Authentication:
-
Lambdaauthorizer (opens in a new tab)-
Authentication: 3rd-party (invoked by
Lambdaauthorizer) -
Authorization:
Lambdafunction -
Authorizer type
-
TOKENauthorizerToken-based
Lambdaauthorizer receives the caller's identity in a bearer token, such as aJWTor anOAuthtoken. -
REQUESTauthorizerRequest parameter-based
Lambdaauthorizer receives the caller's identity in a combination of headers, query string parameters,stageVariables, and$contextvariables.WebSocketonly supportsREQUESTauthorizer.
-
-
-
-
-
4XXErrornumber of client-side errors captured in a given period
-
5XXErrornumber of server-side errors captured in a given period
-
Counttotal number of
APIrequests in a given period -
IntegrationLatencythe responsiveness of the backend
-
Latencythe overall responsiveness of your
APIcalls -
CacheHitCount&CacheMissCountoptimize cache capacities to achieve a desired performance.
-
-
CORS-
To enable
CORSsupport, you may or may not need to implement theCORSpreflight response depending on the situation.-
LambdaorHTTPnon-proxy integrations andAWSservice integrationsManual adding
CORSresponse headers could be needed -
LambdaorHTTPproxy integrationsManual adding
CORSresponse headers is required
-
-
-
Resources
SAM
-
The declaration
Transform: AWS::Serverless-2016-10-31is required forSAMtemplate files. -
Globalssection is unique toSAMtemplates. -
Resource type
AWS::Serverless::ApiAPI 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
LambdaLayerVersion that contains library or runtime code needed by aLambdaFunction.
- Creates a
AWS::Serverless::SimpleTable- a
DynamoDBtable with a single attribute primary key.
- a
AWS::Serverless::StateMachine- an
Step Functionsstate machine
- an
-
Installation
-
Notes
- Use
SAM CLIfor localLambdafunction development. (sam local invoke) - Don't use
SAM CLIfor deployment as it creates additional resources. - Use
CloudFormationfor unified deployment and provisioning. - Use container image for deployment but not for local development as it's slow to build image,
IntelliJalso does not support debuggingLambdafunction packaged as an image.
- Use
-
Resources
CDK (Cloud Development Kit)
-
AssetsAssetsare 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.Assetscan represent any artifact that the app needs to operate. -
Bootstrapping- Deploying AWS
CDKapps into an AWS environment (a combination of an AWS account and region) may require that you provision resources the AWSCDKneeds to perform the deployment. These resources include anS3bucket for storing files andIAMroles 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 Tierusage 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 billingfeature inAWS Organizationsto 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
keysandvaluesare case sensitive. - Using
Tagsto 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
endpointsandquotas -
AWS Documentation - Service Authorization Reference (opens in a new tab)
Service Authorization Referenceprovides a list of theactions, resources, and condition keys that are supported by each AWS service. You can specify actions, resources, and condition keys inIAMpolicies to manage access to AWS resources.