Slide 1

Slide 1 text

Money saving tips for the frugal serverless developer Yan Cui @theburningmonk

Slide 2

Slide 2 text

Yan Cui http://theburningmonk.com @theburningmonk AWS user since 2010

Slide 3

Slide 3 text

Developer Advocate @ Yan Cui http://theburningmonk.com @theburningmonk

Slide 4

Slide 4 text

Yan Cui http://theburningmonk.com @theburningmonk Independent Consultant

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Billing alarms

Slide 7

Slide 7 text

Everyone should use billing alarms.

Slide 8

Slide 8 text

They are not perfect. But they can still save your a$$.

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Keeping logging cost under control

Slide 13

Slide 13 text

CloudWatch often costs much more than your core application.

Slide 14

Slide 14 text

As cost goes up, value goes down.

Slide 15

Slide 15 text

How to keep CloudWatch Logs cost under control 1. Do structured logging.

Slide 16

Slide 16 text

How to keep CloudWatch Logs cost under control 1. Do structured logging. DEBUG INFO WARN ERROR Detailed events for debugging application. General information that highlights progress of application. Potential problems, but doesn’t stop application from working. Issues that require immediate attention.

Slide 17

Slide 17 text

How to keep CloudWatch Logs cost under control 1. Do structured logging. Log at INFO or above in production. DEBUG INFO WARN ERROR Detailed events for debugging application. General information that highlights progress of application. Potential problems, but doesn’t stop application from working. Issues that require immediate attention.

Slide 18

Slide 18 text

How to keep CloudWatch Logs cost under control 1. Do structured logging. Log at INFO or above in production. 2. Sample DEBUG logs in production. e.g. 5% of invocations.

Slide 19

Slide 19 text

How to keep CloudWatch Logs cost under control 1. Do structured logging. Log at INFO or above in production. 2. Sample DEBUG logs in production. e.g. 5% of invocations. 3. Set log retention to 30 days.

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

CloudWatch Logs AWS Lambda AWS Lambda stdout asynchronously invokes any log aggregation service

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

CloudWatch Logs AWS Lambda AWS Lambda stdout asynchronously invokes any log aggregation service double paying for logs

Slide 24

Slide 24 text

Lambda Extensions + Telemetry API

Slide 25

Slide 25 text

https://docs.aws.amazon.com/lambda/latest/dg/telemetry-api.html

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

CloudWatch Logs AWS Lambda

Slide 28

Slide 28 text

https://lumigo.io/blog/lumigo-launches-log-management

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

DEBUG INFO WARN platform.initStart platform.start platform.initRuntimeDone platform.initReport platform.runtimeDone platform.report unhandled exception

Slide 35

Slide 35 text

DEBUG INFO WARN platform.initStart platform.start platform.initRuntimeDone platform.initReport platform.runtimeDone platform.report unhandled exception

Slide 36

Slide 36 text

Right-sizing Lambda memory

Slide 37

Slide 37 text

More memory = more CPU = more network bandwidth

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Easy to be wrong by an order of magnitude.

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Right-sizing Lambda functions

Slide 43

Slide 43 text

https://github.com/alexcasalboni/aws-lambda-power-tuning

Slide 44

Slide 44 text

Use ARM architecture

Slide 45

Slide 45 text

25% cheaper

Slide 46

Slide 46 text

Performance may vary…

Slide 47

Slide 47 text

Best for functions with a lot IO wait time.

Slide 48

Slide 48 text

Caching

Slide 49

Slide 49 text

Caching is a cheat code for building performant & scalable applications.

Slide 50

Slide 50 text

Route53 CloudFront API Gateway Lambda DynamoDB

Slide 51

Slide 51 text

Route53 CloudFront API Gateway Lambda DynamoDB client-side caching

Slide 52

Slide 52 text

Route53 CloudFront API Gateway Lambda DynamoDB client-side caching edge caching

Slide 53

Slide 53 text

Route53 CloudFront API Gateway Lambda DynamoDB client-side caching edge caching application-level caching

Slide 54

Slide 54 text

Route53 CloudFront API Gateway Lambda DynamoDB client-side caching edge caching application-level caching ElastiCache

Slide 55

Slide 55 text

Route53 CloudFront API Gateway Lambda DynamoDB client-side caching edge caching application-level caching Momento

Slide 56

Slide 56 text

Route53 TTL

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Use longer TTL for stable domains

Slide 59

Slide 59 text

Avoid CORS

Slide 60

Slide 60 text

Enabling CORS for API Gateway is easy

Slide 61

Slide 61 text

Enabling CORS for API Gateway is easy But you still pay for those CORS requests!

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

You might be double paying for every user request to your API…

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Choose the right service

Slide 66

Slide 66 text

Every architectural decision is a buying decision.

Slide 67

Slide 67 text

Using the wrong service can be very costly.

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

Assuming 1KB per request

Slide 71

Slide 71 text

Assuming 1KB per request

Slide 72

Slide 72 text

Services that charge by uptime are order(s) of magnitude cheaper at scale.

Slide 73

Slide 73 text

Assuming 1MB per request 😂 $53,837.87 $68.99

Slide 74

Slide 74 text

www.thefrugalarchitect.com

Slide 75

Slide 75 text

Law I. Make Cost a Non-functional Requirement. Law II. Systems that Last Align Cost to Business. Law III. Architecting is a Series of Trade-offs. Law IV. Unobserved Systems Lead to Unknown Costs. Law V. Cost Aware Architectures Implement Cost Controls. Law VI. Cost Optimization is Incremental. Law VII. Unchallenged Success Leads to Assumptions.

Slide 76

Slide 76 text

Law I. Make Cost a Non-functional Requirement. Law II. Systems that Last Align Cost to Business. Law III. Architecting is a Series of Trade-offs. Law IV. Unobserved Systems Lead to Unknown Costs. Law V. Cost Aware Architectures Implement Cost Controls. Law VI. Cost Optimization is Incremental. Law VII. Unchallenged Success Leads to Assumptions.

Slide 77

Slide 77 text

IOT core AppSync API Gateway Messages Connection Time $2 per million $0.08 per million mins $0.25 per million mins $1 per million $0.08 per million mins $1 per million

Slide 78

Slide 78 text

Users Connection Time

Slide 79

Slide 79 text

Users Connection Time Revenue

Slide 80

Slide 80 text

Users Connection Time Revenue Engagement

Slide 81

Slide 81 text

Users Connection Time Revenue Engagement

Slide 82

Slide 82 text

www.gomomento.com/services/topics

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

IOT core AppSync API Gateway Messages Connection Time $2 per million $0.08 per million mins $0.25 per million mins $1 per million $0.08 per million mins $1 per million Momento - - Data Transfer $0.5 / GB EC2 rates EC2 rates EC2 rates

Slide 85

Slide 85 text

Simplify your architecture

Slide 86

Slide 86 text

Avoid unnecessary moving parts to your architecture.

Slide 87

Slide 87 text

? ? Synchronous

Slide 88

Slide 88 text

? ? Asynchronous

Slide 89

Slide 89 text

Every component in your architecture should serve a purpose and provide a ROI.

Slide 90

Slide 90 text

The most dangerous phrase in the language is "we've always done it this way". - Grace Hopper

Slide 91

Slide 91 text

Function URLs

Slide 92

Slide 92 text

Function URL

Slide 93

Slide 93 text

If you’re not using API Gateway features (e.g. Cognito authoriser, request models, direct integration)

Slide 94

Slide 94 text

Or, if you’re facing API Gateway limits (e.g. 29s timeout, no response streaming)

Slide 95

Slide 95 text

Have to write Lambdaliths

Slide 96

Slide 96 text

Have to write Lambdaliths (No per-endpoint metrics & alerts, no fi ne-grained access control, no per-endpoint auth)

Slide 97

Slide 97 text

Have to write Lambdaliths (No per-endpoint metrics & alerts, no fi ne-grained access control, no per-endpoint auth) (Large frameworks a ff ect cold start performance)

Slide 98

Slide 98 text

Best for public or internal APIs

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

Functionless

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No Lambda = no cold starts

Slide 103

Slide 103 text

No Lambda = no Lambda costs

Slide 104

Slide 104 text

EventBridge Pipes

Slide 105

Slide 105 text

EventBridge Pipes

Slide 106

Slide 106 text

EventBridge Pipes Transform

Slide 107

Slide 107 text

Use Lambda functions to transform data, NOT transport data

Slide 108

Slide 108 text

OpenSearch

Slide 109

Slide 109 text

No-Code ETL OpenSearch

Slide 110

Slide 110 text

AppSync EventBridge OpenSearch

Slide 111

Slide 111 text

Step Functions EventBridge OpenSearch

Slide 112

Slide 112 text

Every component in your architecture should serve a purpose and provide a ROI.

Slide 113

Slide 113 text

Direct client access to AWS

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

No content

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

Only allow access if hash key matches cognito sub

Slide 118

Slide 118 text

Not for the feint hearted…

Slide 119

Slide 119 text

When not to use this:

Slide 120

Slide 120 text

https://theburningmonk.com/2023/12/direct-access-for-frontend-apps-to-aws-services

Slide 121

Slide 121 text

1. Billing alarms 2. Keeping logging cost under control 3. Right-sizing Lambda functions 4. Caching 5. Route53 TTL 6. Avoid CORS 7. Choosing the right service 8. Simplify your architecture 9. Function URLs 10. Functionless 11. Direct client access to AWS

Slide 122

Slide 122 text

productionreadyserverless.com Join 20+ AWS Heroes & Community Builders and 1000+ happy students in levelling up your serverless game.

Slide 123

Slide 123 text

Questions?