SlideShare a Scribd company logo
1 of 58
Download to read offline
How to send gzipped requests
with boto3
Luciano Mammino ( )
@loige
AWS UserGroup Dublin
2021-07-01
loige.link/gzip-boto3
1
loige.link/gzip-boto3
Get these slides!
loige 2
Let me introduce myself first...
3
Let me introduce myself first...
I'm Luciano ( 🍕🍝) 👋
3
Let me introduce myself first...
I'm Luciano ( 🍕🍝) 👋
Senior Architect @ fourTheorem (Dublin )
3
Let me introduce myself first...
I'm Luciano ( 🍕🍝) 👋
Senior Architect @ fourTheorem (Dublin )
nodejsdp.link
Co-Author of Node.js Design Patterns  👉
3
Let me introduce myself first...
I'm Luciano ( 🍕🍝) 👋
Senior Architect @ fourTheorem (Dublin )
nodejsdp.link
Co-Author of Node.js Design Patterns  👉
Connect with me:
 
  (blog)
  (twitter)
  (twitch)
  (github)
loige.co
@loige
loige
lmammino 3
We are business focused technologists that
deliver.
 |  |
Accelerated Serverless AI as a Service Platform Modernisation
We are hiring: do you want to ?
work with us
loige 4
loige
In the previous episodes...
SLIC WATCH:             
SLIDES:     
fth.link/slic-watch
fth.link/o11y-no-pain
5
loige
⚠   ALARM "Custom-Metrics-MetricsFunctionErrorsAlarm" in EU (Ireland)
Threshold crossed: 1 out of the last 1 datapoints [84.0 (23/06/21 09:30:00)] was
greater than or equal to the threshold (1.0) (minimum 1 datapoint for OK ->
ALARM transition).
@wake_me_up_bot
6
loige 7
loige 8
loige
This guy was failing... a lot!
8
loige 9
for event in payload['logEvents']:
# ...
cw_client.put_metric_data(...)
loige 10
for event in payload['logEvents']:
# ...
cw_client.put_metric_data(...)
loige
Sending 1 metric per log line... 🙈
10
[
{
'MetricName': 'SomeMetric1',
'Dimensions': [
{
'Name': 'Dimension1Name',
'Value': 'Dimension1Value'
},
# Up to other 9 dimensions here ...
],
'Unit': 'Count',
'Values': [217, 220, 221], # Up to 150 items here ...
'Timestamp': 1624290910000
},
# Up to other 19 metric items here ...
]
loige 11
[
{
'MetricName': 'SomeMetric1',
'Dimensions': [
{
'Name': 'Dimension1Name',
'Value': 'Dimension1Value'
},
# Up to other 9 dimensions here ...
],
'Unit': 'Count',
'Values': [217, 220, 221], # Up to 150 items here ...
'Timestamp': 1624290910000
},
# Up to other 19 metric items here ...
]
loige
⚠Payload size
limit: 40 KB
11
loige 12
loige
🤔
12
loige
Maybe boto3 gzips the data
automatically! 😏
13
import boto3
import gzip
endpoint_url = "http://localhost:8000/"
cw_client = boto3.client('cloudwatch', endpoint_url=endpoint_url, use_ssl=False)
cw_client.put_metric_data(
MetricData = [
{
'MetricName': 'TEST_BOTO',
'Dimensions': [
{
'Name': 'APP_VERSION',
'Value': '1.0'
},
],
'Unit': 'None',
'Value': 17
},
],
Namespace='BotoTest'
)
loige 14
import boto3
import gzip
endpoint_url = "http://localhost:8000/"
cw_client = boto3.client('cloudwatch', endpoint_url=endpoint_url, use_ssl=False)
cw_client.put_metric_data(
MetricData = [
{
'MetricName': 'TEST_BOTO',
'Dimensions': [
{
'Name': 'APP_VERSION',
'Value': '1.0'
},
],
'Unit': 'None',
'Value': 17
},
],
Namespace='BotoTest'
)
loige 14
import boto3
import gzip
endpoint_url = "http://localhost:8000/"
cw_client = boto3.client('cloudwatch', endpoint_url=endpoint_url, use_ssl=False)
cw_client.put_metric_data(
MetricData = [
{
'MetricName': 'TEST_BOTO',
'Dimensions': [
{
'Name': 'APP_VERSION',
'Value': '1.0'
},
],
'Unit': 'None',
'Value': 17
},
],
Namespace='BotoTest'
)
loige 14
loige 15
loige
... and there is no magic flag like
GzipPayload=True! 😭
16
loige
Can we extend boto3 somehow? 🤔
17
loige
boto3 has an event system! 🤩
youtu.be/eM8uoGJO2AI
@thekyleknapp
18
import boto3
lambda_client = boto3.client('lambda')
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
# get the event system for the lambda_client
event_system = lambda_client.meta.events
# attach an event handler to the client for
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
# invoke a lambda function
lambda_client.invoke(FunctionName='my-function')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
loige 19
import boto3
lambda_client = boto3.client('lambda')
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
# get the event system for the lambda_client
event_system = lambda_client.meta.events
# attach an event handler to the client for
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
# invoke a lambda function
lambda_client.invoke(FunctionName='my-function')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import boto3
lambda_client = boto3.client('lambda')
1
2
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
loige 19
import boto3
lambda_client = boto3.client('lambda')
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
# get the event system for the lambda_client
event_system = lambda_client.meta.events
# attach an event handler to the client for
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
# invoke a lambda function
lambda_client.invoke(FunctionName='my-function')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import boto3
lambda_client = boto3.client('lambda')
1
2
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
5
6
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
loige 19
import boto3
lambda_client = boto3.client('lambda')
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
# get the event system for the lambda_client
event_system = lambda_client.meta.events
# attach an event handler to the client for
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
# invoke a lambda function
lambda_client.invoke(FunctionName='my-function')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import boto3
lambda_client = boto3.client('lambda')
1
2
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
5
6
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# get the event system for the lambda_client
event_system = lambda_client.meta.events
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
9
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
loige 19
import boto3
lambda_client = boto3.client('lambda')
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
# get the event system for the lambda_client
event_system = lambda_client.meta.events
# attach an event handler to the client for
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
# invoke a lambda function
lambda_client.invoke(FunctionName='my-function')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import boto3
lambda_client = boto3.client('lambda')
1
2
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
5
6
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# get the event system for the lambda_client
event_system = lambda_client.meta.events
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
9
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# attach an event handler to the client for
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
12
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
loige 19
import boto3
lambda_client = boto3.client('lambda')
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
# get the event system for the lambda_client
event_system = lambda_client.meta.events
# attach an event handler to the client for
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
# invoke a lambda function
lambda_client.invoke(FunctionName='my-function')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import boto3
lambda_client = boto3.client('lambda')
1
2
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
5
6
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# get the event system for the lambda_client
event_system = lambda_client.meta.events
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
9
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# attach an event handler to the client for
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
12
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# invoke a lambda function
lambda_client.invoke(FunctionName='my-function')
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
15
16
loige 19
import boto3
lambda_client = boto3.client('lambda')
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
# get the event system for the lambda_client
event_system = lambda_client.meta.events
# attach an event handler to the client for
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
# invoke a lambda function
lambda_client.invoke(FunctionName='my-function')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import boto3
lambda_client = boto3.client('lambda')
1
2
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
5
6
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# get the event system for the lambda_client
event_system = lambda_client.meta.events
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
9
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# attach an event handler to the client for
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
12
13
14
# invoke a lambda function
15
lambda_client.invoke(FunctionName='my-function')
16
# invoke a lambda function
lambda_client.invoke(FunctionName='my-function')
import boto3
1
2
lambda_client = boto3.client('lambda')
3
4
# our event handler
5
def add_xtrace_header(request, **kwargs):
6
request.headers.add_header('x-trace-id', 'trace-trace')
7
8
# get the event system for the lambda_client
9
event_system = lambda_client.meta.events
10
11
# attach an event handler to the client for
12
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
13
14
15
16
import boto3
lambda_client = boto3.client('lambda')
# our event handler
def add_xtrace_header(request, **kwargs):
request.headers.add_header('x-trace-id', 'trace-trace')
# get the event system for the lambda_client
event_system = lambda_client.meta.events
# attach an event handler to the client for
event_system.register('before-sign.lambda.Invoke', add_xtrace_header)
# invoke a lambda function
lambda_client.invoke(FunctionName='my-function')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
loige 19
loige
Event naming convention
<event-type>.<service-name>.<operation-name>
20
loige
Event naming convention
<event-type>.<service-name>.<operation-name>
provide-client-params
request-created
before-sign
before-send
response-received
20
loige
Event naming convention
<event-type>.<service-name>.<operation-name>
provide-client-params
request-created
before-sign
before-send
response-received
s3
cloudwatch
lambda
...
20
loige
Event naming convention
<event-type>.<service-name>.<operation-name>
provide-client-params
request-created
before-sign
before-send
response-received
s3
cloudwatch
lambda
...
ListBuckets
PutMetricData
Invoke
...
20
loige
You can be a 🌟too!
 
* (every event)
after-call.*.* (all responses)
after-call.lambda.* (all responses for lambda)
21
loige
OK, now we know enough to write
our own event handler for gzip
compression! 🤓
22
import boto3
import gzip
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
cw_client.put_metric_data(...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
loige 23
import boto3
import gzip
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
cw_client.put_metric_data(...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
loige 23
import boto3
import gzip
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
cw_client.put_metric_data(...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
import gzip
import boto3
1
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
loige 23
import boto3
import gzip
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
cw_client.put_metric_data(...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
import gzip
import boto3
1
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
import boto3
1
import gzip
2
3
4
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
loige 23
import boto3
import gzip
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
cw_client.put_metric_data(...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
import gzip
import boto3
1
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
import boto3
1
import gzip
2
3
4
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
7
8
9
10
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
loige 23
import boto3
import gzip
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
cw_client.put_metric_data(...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
import gzip
import boto3
1
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
import boto3
1
import gzip
2
3
4
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
7
8
9
10
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
request.headers.add_header('Content-Encoding', 'gzip')
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
loige 23
import boto3
import gzip
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
cw_client.put_metric_data(...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
import gzip
import boto3
1
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
import boto3
1
import gzip
2
3
4
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
7
8
9
10
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
request.headers.add_header('Content-Encoding', 'gzip')
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
10
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
loige 23
import boto3
import gzip
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
cw_client.put_metric_data(...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
import gzip
import boto3
1
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
import boto3
1
import gzip
2
3
4
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
7
8
9
10
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
request.headers.add_header('Content-Encoding', 'gzip')
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
10
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
13
14
15
16
cw_client.put_metric_data(...)
17
loige 23
import boto3
import gzip
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
cw_client.put_metric_data(...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
import gzip
import boto3
1
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
import boto3
1
import gzip
2
3
4
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
7
8
9
10
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
request.headers.add_header('Content-Encoding', 'gzip')
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
10
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
13
14
15
16
cw_client.put_metric_data(...)
17 cw_client.put_metric_data(...)
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
17
loige 23
import boto3
import gzip
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
cw_client.put_metric_data(...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
import gzip
import boto3
1
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
import boto3
1
import gzip
2
3
4
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
7
8
9
10
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
request.headers.add_header('Content-Encoding', 'gzip')
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
10
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
cw_client.put_metric_data(...)
17
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
13
14
15
16
cw_client.put_metric_data(...)
17 cw_client.put_metric_data(...)
import boto3
1
import gzip
2
3
cw_client = boto3.client('cloudwatch')
4
event_system = cw_client.meta.events
5
6
# Gzip handler
7
def gzip_request_body(request, **kwargs):
8
request.headers.add_header('Content-Encoding', 'gzip')
9
gzipped_body = gzip.compress(request.body)
10
request.data = gzipped_body
11
12
# registers the custom handler
13
event_system.register('before-sign.cloudwatch.PutMetricData',
14
gzip_request_body)
15
16
17
import boto3
import gzip
cw_client = boto3.client('cloudwatch')
event_system = cw_client.meta.events
# Gzip handler
def gzip_request_body(request, **kwargs):
request.headers.add_header('Content-Encoding', 'gzip')
gzipped_body = gzip.compress(request.body)
request.data = gzipped_body
# registers the custom handler
event_system.register('before-sign.cloudwatch.PutMetricData',
gzip_request_body)
cw_client.put_metric_data(...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
loige 23
loige 24
loige
Other potential use cases
Log data before/after it is sent to AWS
Add additional headers to AWS requests (tracing)
Additional input validation (your custom rules)
Payload enrichment (e.g. make sure certain tags exist)
25
loige
What if you don't use Python?
Customizing the AWS SDK for Go V2 Client Requests
Introducing Middleware Stack in Modular AWS SDK for
JavaScript
Handlers and Middleware in the AWS SDK for PHP Version 3
26
loige
What did we learn?
Always have alarms for your lambdas!
(have you checked already? 😉)
You can use Gzip compression to send big payloads to AWS
Boto3 is extensible through its event system!
SLIC Watch
27
loige
Do you think boto3 should make it easier to
send gzipped payloads?
👍UPVOTE this issue: github.com/boto/botocore/issues/2425
28
loige
Do you want more details?
loige.link/gzip-boto3-article
29
Cover picturea by on
Thanks doggie by Stefanie Shank
Moritz Mentges Unsplash
loige
nodejsdp.link
loige.link/gzip-boto3
30

More Related Content

What's hot

What's hot (20)

Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.js
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
$q and Promises in AngularJS
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS
 
JavaScript Promise
JavaScript PromiseJavaScript Promise
JavaScript Promise
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
 
Promise pattern
Promise patternPromise pattern
Promise pattern
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
 
Practical JavaScript Promises
Practical JavaScript PromisesPractical JavaScript Promises
Practical JavaScript Promises
 
Any event intro
Any event introAny event intro
Any event intro
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitives
 
Beyond Profilers: Tracing Node.js Transactions
Beyond Profilers: Tracing Node.js TransactionsBeyond Profilers: Tracing Node.js Transactions
Beyond Profilers: Tracing Node.js Transactions
 
Présentation de HomeKit
Présentation de HomeKitPrésentation de HomeKit
Présentation de HomeKit
 
Getting Comfortable with JS Promises
Getting Comfortable with JS PromisesGetting Comfortable with JS Promises
Getting Comfortable with JS Promises
 
Testing your infrastructure with litmus
Testing your infrastructure with litmusTesting your infrastructure with litmus
Testing your infrastructure with litmus
 

Similar to How to send gzipped requests with boto3

Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2
Alessandro Molina
 
Behind the scenes of Scaleway Functions : when Kubernetes meets our products
Behind the scenes of Scaleway Functions : when Kubernetes meets our productsBehind the scenes of Scaleway Functions : when Kubernetes meets our products
Behind the scenes of Scaleway Functions : when Kubernetes meets our products
Scaleway
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
Wesley Beary
 
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
CODE BLUE
 

Similar to How to send gzipped requests with boto3 (20)

Mini Curso de Django
Mini Curso de DjangoMini Curso de Django
Mini Curso de Django
 
How to build twitter bot using golang from scratch
How to build twitter bot using golang from scratchHow to build twitter bot using golang from scratch
How to build twitter bot using golang from scratch
 
Mini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico CesMini Curso Django Ii Congresso Academico Ces
Mini Curso Django Ii Congresso Academico Ces
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Behind the scenes of Scaleway Functions : when Kubernetes meets our products
Behind the scenes of Scaleway Functions : when Kubernetes meets our productsBehind the scenes of Scaleway Functions : when Kubernetes meets our products
Behind the scenes of Scaleway Functions : when Kubernetes meets our products
 
Webinar - 2020-09-23 - Escape the ticketing turmoil with Teleport PagerDuty &...
Webinar - 2020-09-23 - Escape the ticketing turmoil with Teleport PagerDuty &...Webinar - 2020-09-23 - Escape the ticketing turmoil with Teleport PagerDuty &...
Webinar - 2020-09-23 - Escape the ticketing turmoil with Teleport PagerDuty &...
 
Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)Python from zero to hero (Twitter Explorer)
Python from zero to hero (Twitter Explorer)
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
 
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeGDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
 
Build resource server &amp; client for OCF Cloud (2018.8.30)
Build resource server &amp; client for OCF Cloud (2018.8.30)Build resource server &amp; client for OCF Cloud (2018.8.30)
Build resource server &amp; client for OCF Cloud (2018.8.30)
 
Building Your First App with MongoDB Stitch
Building Your First App with MongoDB StitchBuilding Your First App with MongoDB Stitch
Building Your First App with MongoDB Stitch
 
Structure your Play application with the cake pattern (and test it)
Structure your Play application with the cake pattern (and test it)Structure your Play application with the cake pattern (and test it)
Structure your Play application with the cake pattern (and test it)
 
Tasks: you gotta know how to run them
Tasks: you gotta know how to run themTasks: you gotta know how to run them
Tasks: you gotta know how to run them
 
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
[CB16] Esoteric Web Application Vulnerabilities by Andrés Riancho
 
Serverless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applicationsServerless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applications
 
Monitoring at scale: Migrating to Prometheus at Fastly
Monitoring at scale: Migrating to Prometheus at FastlyMonitoring at scale: Migrating to Prometheus at Fastly
Monitoring at scale: Migrating to Prometheus at Fastly
 

More from Luciano Mammino

More from Luciano Mammino (20)

Did you know JavaScript has iterators? DublinJS
Did you know JavaScript has iterators? DublinJSDid you know JavaScript has iterators? DublinJS
Did you know JavaScript has iterators? DublinJS
 
What I learned by solving 50 Advent of Code challenges in Rust - RustNation U...
What I learned by solving 50 Advent of Code challenges in Rust - RustNation U...What I learned by solving 50 Advent of Code challenges in Rust - RustNation U...
What I learned by solving 50 Advent of Code challenges in Rust - RustNation U...
 
Building an invite-only microsite with Next.js & Airtable - ReactJS Milano
Building an invite-only microsite with Next.js & Airtable - ReactJS MilanoBuilding an invite-only microsite with Next.js & Airtable - ReactJS Milano
Building an invite-only microsite with Next.js & Airtable - ReactJS Milano
 
From Node.js to Design Patterns - BuildPiper
From Node.js to Design Patterns - BuildPiperFrom Node.js to Design Patterns - BuildPiper
From Node.js to Design Patterns - BuildPiper
 
Let's build a 0-cost invite-only website with Next.js and Airtable!
Let's build a 0-cost invite-only website with Next.js and Airtable!Let's build a 0-cost invite-only website with Next.js and Airtable!
Let's build a 0-cost invite-only website with Next.js and Airtable!
 
Everything I know about S3 pre-signed URLs
Everything I know about S3 pre-signed URLsEverything I know about S3 pre-signed URLs
Everything I know about S3 pre-signed URLs
 
Serverless for High Performance Computing
Serverless for High Performance ComputingServerless for High Performance Computing
Serverless for High Performance Computing
 
Serverless for High Performance Computing
Serverless for High Performance ComputingServerless for High Performance Computing
Serverless for High Performance Computing
 
JavaScript Iteration Protocols - Workshop NodeConf EU 2022
JavaScript Iteration Protocols - Workshop NodeConf EU 2022JavaScript Iteration Protocols - Workshop NodeConf EU 2022
JavaScript Iteration Protocols - Workshop NodeConf EU 2022
 
Building an invite-only microsite with Next.js & Airtable
Building an invite-only microsite with Next.js & AirtableBuilding an invite-only microsite with Next.js & Airtable
Building an invite-only microsite with Next.js & Airtable
 
Let's take the monolith to the cloud 🚀
Let's take the monolith to the cloud 🚀Let's take the monolith to the cloud 🚀
Let's take the monolith to the cloud 🚀
 
A look inside the European Covid Green Certificate - Rust Dublin
A look inside the European Covid Green Certificate - Rust DublinA look inside the European Covid Green Certificate - Rust Dublin
A look inside the European Covid Green Certificate - Rust Dublin
 
Monoliths to the cloud!
Monoliths to the cloud!Monoliths to the cloud!
Monoliths to the cloud!
 
The senior dev
The senior devThe senior dev
The senior dev
 
Node.js: scalability tips - Azure Dev Community Vijayawada
Node.js: scalability tips - Azure Dev Community VijayawadaNode.js: scalability tips - Azure Dev Community Vijayawada
Node.js: scalability tips - Azure Dev Community Vijayawada
 
A look inside the European Covid Green Certificate (Codemotion 2021)
A look inside the European Covid Green Certificate (Codemotion 2021)A look inside the European Covid Green Certificate (Codemotion 2021)
A look inside the European Covid Green Certificate (Codemotion 2021)
 
AWS Observability Made Simple
AWS Observability Made SimpleAWS Observability Made Simple
AWS Observability Made Simple
 
Semplificare l'observability per progetti Serverless
Semplificare l'observability per progetti ServerlessSemplificare l'observability per progetti Serverless
Semplificare l'observability per progetti Serverless
 
Finding a lost song with Node.js and async iterators - NodeConf Remote 2021
Finding a lost song with Node.js and async iterators - NodeConf Remote 2021Finding a lost song with Node.js and async iterators - NodeConf Remote 2021
Finding a lost song with Node.js and async iterators - NodeConf Remote 2021
 
Finding a lost song with Node.js and async iterators - EnterJS 2021
Finding a lost song with Node.js and async iterators - EnterJS 2021Finding a lost song with Node.js and async iterators - EnterJS 2021
Finding a lost song with Node.js and async iterators - EnterJS 2021
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 

How to send gzipped requests with boto3

  • 1. How to send gzipped requests with boto3 Luciano Mammino ( ) @loige AWS UserGroup Dublin 2021-07-01 loige.link/gzip-boto3 1
  • 3. Let me introduce myself first... 3
  • 4. Let me introduce myself first... I'm Luciano ( 🍕🍝) 👋 3
  • 5. Let me introduce myself first... I'm Luciano ( 🍕🍝) 👋 Senior Architect @ fourTheorem (Dublin ) 3
  • 6. Let me introduce myself first... I'm Luciano ( 🍕🍝) 👋 Senior Architect @ fourTheorem (Dublin ) nodejsdp.link Co-Author of Node.js Design Patterns  👉 3
  • 7. Let me introduce myself first... I'm Luciano ( 🍕🍝) 👋 Senior Architect @ fourTheorem (Dublin ) nodejsdp.link Co-Author of Node.js Design Patterns  👉 Connect with me:     (blog)   (twitter)   (twitch)   (github) loige.co @loige loige lmammino 3
  • 8. We are business focused technologists that deliver.  |  | Accelerated Serverless AI as a Service Platform Modernisation We are hiring: do you want to ? work with us loige 4
  • 9. loige In the previous episodes... SLIC WATCH:              SLIDES:      fth.link/slic-watch fth.link/o11y-no-pain 5
  • 10. loige ⚠   ALARM "Custom-Metrics-MetricsFunctionErrorsAlarm" in EU (Ireland) Threshold crossed: 1 out of the last 1 datapoints [84.0 (23/06/21 09:30:00)] was greater than or equal to the threshold (1.0) (minimum 1 datapoint for OK -> ALARM transition). @wake_me_up_bot 6
  • 13. loige This guy was failing... a lot! 8
  • 15. for event in payload['logEvents']: # ... cw_client.put_metric_data(...) loige 10
  • 16. for event in payload['logEvents']: # ... cw_client.put_metric_data(...) loige Sending 1 metric per log line... 🙈 10
  • 17. [ { 'MetricName': 'SomeMetric1', 'Dimensions': [ { 'Name': 'Dimension1Name', 'Value': 'Dimension1Value' }, # Up to other 9 dimensions here ... ], 'Unit': 'Count', 'Values': [217, 220, 221], # Up to 150 items here ... 'Timestamp': 1624290910000 }, # Up to other 19 metric items here ... ] loige 11
  • 18. [ { 'MetricName': 'SomeMetric1', 'Dimensions': [ { 'Name': 'Dimension1Name', 'Value': 'Dimension1Value' }, # Up to other 9 dimensions here ... ], 'Unit': 'Count', 'Values': [217, 220, 221], # Up to 150 items here ... 'Timestamp': 1624290910000 }, # Up to other 19 metric items here ... ] loige ⚠Payload size limit: 40 KB 11
  • 21. loige Maybe boto3 gzips the data automatically! 😏 13
  • 22. import boto3 import gzip endpoint_url = "http://localhost:8000/" cw_client = boto3.client('cloudwatch', endpoint_url=endpoint_url, use_ssl=False) cw_client.put_metric_data( MetricData = [ { 'MetricName': 'TEST_BOTO', 'Dimensions': [ { 'Name': 'APP_VERSION', 'Value': '1.0' }, ], 'Unit': 'None', 'Value': 17 }, ], Namespace='BotoTest' ) loige 14
  • 23. import boto3 import gzip endpoint_url = "http://localhost:8000/" cw_client = boto3.client('cloudwatch', endpoint_url=endpoint_url, use_ssl=False) cw_client.put_metric_data( MetricData = [ { 'MetricName': 'TEST_BOTO', 'Dimensions': [ { 'Name': 'APP_VERSION', 'Value': '1.0' }, ], 'Unit': 'None', 'Value': 17 }, ], Namespace='BotoTest' ) loige 14
  • 24. import boto3 import gzip endpoint_url = "http://localhost:8000/" cw_client = boto3.client('cloudwatch', endpoint_url=endpoint_url, use_ssl=False) cw_client.put_metric_data( MetricData = [ { 'MetricName': 'TEST_BOTO', 'Dimensions': [ { 'Name': 'APP_VERSION', 'Value': '1.0' }, ], 'Unit': 'None', 'Value': 17 }, ], Namespace='BotoTest' ) loige 14
  • 26. loige ... and there is no magic flag like GzipPayload=True! 😭 16
  • 27. loige Can we extend boto3 somehow? 🤔 17
  • 28. loige boto3 has an event system! 🤩 youtu.be/eM8uoGJO2AI @thekyleknapp 18
  • 29. import boto3 lambda_client = boto3.client('lambda') # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') # get the event system for the lambda_client event_system = lambda_client.meta.events # attach an event handler to the client for event_system.register('before-sign.lambda.Invoke', add_xtrace_header) # invoke a lambda function lambda_client.invoke(FunctionName='my-function') 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 loige 19
  • 30. import boto3 lambda_client = boto3.client('lambda') # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') # get the event system for the lambda_client event_system = lambda_client.meta.events # attach an event handler to the client for event_system.register('before-sign.lambda.Invoke', add_xtrace_header) # invoke a lambda function lambda_client.invoke(FunctionName='my-function') 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import boto3 lambda_client = boto3.client('lambda') 1 2 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 loige 19
  • 31. import boto3 lambda_client = boto3.client('lambda') # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') # get the event system for the lambda_client event_system = lambda_client.meta.events # attach an event handler to the client for event_system.register('before-sign.lambda.Invoke', add_xtrace_header) # invoke a lambda function lambda_client.invoke(FunctionName='my-function') 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import boto3 lambda_client = boto3.client('lambda') 1 2 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 5 6 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 loige 19
  • 32. import boto3 lambda_client = boto3.client('lambda') # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') # get the event system for the lambda_client event_system = lambda_client.meta.events # attach an event handler to the client for event_system.register('before-sign.lambda.Invoke', add_xtrace_header) # invoke a lambda function lambda_client.invoke(FunctionName='my-function') 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import boto3 lambda_client = boto3.client('lambda') 1 2 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 5 6 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # get the event system for the lambda_client event_system = lambda_client.meta.events import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 9 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 loige 19
  • 33. import boto3 lambda_client = boto3.client('lambda') # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') # get the event system for the lambda_client event_system = lambda_client.meta.events # attach an event handler to the client for event_system.register('before-sign.lambda.Invoke', add_xtrace_header) # invoke a lambda function lambda_client.invoke(FunctionName='my-function') 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import boto3 lambda_client = boto3.client('lambda') 1 2 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 5 6 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # get the event system for the lambda_client event_system = lambda_client.meta.events import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 9 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # attach an event handler to the client for event_system.register('before-sign.lambda.Invoke', add_xtrace_header) import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 12 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 loige 19
  • 34. import boto3 lambda_client = boto3.client('lambda') # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') # get the event system for the lambda_client event_system = lambda_client.meta.events # attach an event handler to the client for event_system.register('before-sign.lambda.Invoke', add_xtrace_header) # invoke a lambda function lambda_client.invoke(FunctionName='my-function') 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import boto3 lambda_client = boto3.client('lambda') 1 2 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 5 6 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # get the event system for the lambda_client event_system = lambda_client.meta.events import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 9 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # attach an event handler to the client for event_system.register('before-sign.lambda.Invoke', add_xtrace_header) import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 12 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # invoke a lambda function lambda_client.invoke(FunctionName='my-function') import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 15 16 loige 19
  • 35. import boto3 lambda_client = boto3.client('lambda') # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') # get the event system for the lambda_client event_system = lambda_client.meta.events # attach an event handler to the client for event_system.register('before-sign.lambda.Invoke', add_xtrace_header) # invoke a lambda function lambda_client.invoke(FunctionName='my-function') 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import boto3 lambda_client = boto3.client('lambda') 1 2 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 5 6 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # get the event system for the lambda_client event_system = lambda_client.meta.events import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 9 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # attach an event handler to the client for event_system.register('before-sign.lambda.Invoke', add_xtrace_header) import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 12 13 14 # invoke a lambda function 15 lambda_client.invoke(FunctionName='my-function') 16 # invoke a lambda function lambda_client.invoke(FunctionName='my-function') import boto3 1 2 lambda_client = boto3.client('lambda') 3 4 # our event handler 5 def add_xtrace_header(request, **kwargs): 6 request.headers.add_header('x-trace-id', 'trace-trace') 7 8 # get the event system for the lambda_client 9 event_system = lambda_client.meta.events 10 11 # attach an event handler to the client for 12 event_system.register('before-sign.lambda.Invoke', add_xtrace_header) 13 14 15 16 import boto3 lambda_client = boto3.client('lambda') # our event handler def add_xtrace_header(request, **kwargs): request.headers.add_header('x-trace-id', 'trace-trace') # get the event system for the lambda_client event_system = lambda_client.meta.events # attach an event handler to the client for event_system.register('before-sign.lambda.Invoke', add_xtrace_header) # invoke a lambda function lambda_client.invoke(FunctionName='my-function') 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 loige 19
  • 40. loige You can be a 🌟too!   * (every event) after-call.*.* (all responses) after-call.lambda.* (all responses for lambda) 21
  • 41. loige OK, now we know enough to write our own event handler for gzip compression! 🤓 22
  • 42. import boto3 import gzip cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) cw_client.put_metric_data(...) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 loige 23
  • 43. import boto3 import gzip cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) cw_client.put_metric_data(...) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 loige 23
  • 44. import boto3 import gzip cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) cw_client.put_metric_data(...) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 import gzip import boto3 1 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 loige 23
  • 45. import boto3 import gzip cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) cw_client.put_metric_data(...) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 import gzip import boto3 1 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events import boto3 1 import gzip 2 3 4 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 loige 23
  • 46. import boto3 import gzip cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) cw_client.put_metric_data(...) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 import gzip import boto3 1 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events import boto3 1 import gzip 2 3 4 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 7 8 9 10 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 loige 23
  • 47. import boto3 import gzip cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) cw_client.put_metric_data(...) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 import gzip import boto3 1 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events import boto3 1 import gzip 2 3 4 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 7 8 9 10 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 request.headers.add_header('Content-Encoding', 'gzip') import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 loige 23
  • 48. import boto3 import gzip cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) cw_client.put_metric_data(...) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 import gzip import boto3 1 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events import boto3 1 import gzip 2 3 4 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 7 8 9 10 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 request.headers.add_header('Content-Encoding', 'gzip') import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 gzipped_body = gzip.compress(request.body) request.data = gzipped_body import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 10 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 loige 23
  • 49. import boto3 import gzip cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) cw_client.put_metric_data(...) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 import gzip import boto3 1 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events import boto3 1 import gzip 2 3 4 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 7 8 9 10 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 request.headers.add_header('Content-Encoding', 'gzip') import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 gzipped_body = gzip.compress(request.body) request.data = gzipped_body import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 10 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 13 14 15 16 cw_client.put_metric_data(...) 17 loige 23
  • 50. import boto3 import gzip cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) cw_client.put_metric_data(...) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 import gzip import boto3 1 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events import boto3 1 import gzip 2 3 4 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 7 8 9 10 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 request.headers.add_header('Content-Encoding', 'gzip') import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 gzipped_body = gzip.compress(request.body) request.data = gzipped_body import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 10 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 13 14 15 16 cw_client.put_metric_data(...) 17 cw_client.put_metric_data(...) import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 17 loige 23
  • 51. import boto3 import gzip cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) cw_client.put_metric_data(...) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 import gzip import boto3 1 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events import boto3 1 import gzip 2 3 4 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 7 8 9 10 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 request.headers.add_header('Content-Encoding', 'gzip') import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 gzipped_body = gzip.compress(request.body) request.data = gzipped_body import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 10 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 cw_client.put_metric_data(...) 17 # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 13 14 15 16 cw_client.put_metric_data(...) 17 cw_client.put_metric_data(...) import boto3 1 import gzip 2 3 cw_client = boto3.client('cloudwatch') 4 event_system = cw_client.meta.events 5 6 # Gzip handler 7 def gzip_request_body(request, **kwargs): 8 request.headers.add_header('Content-Encoding', 'gzip') 9 gzipped_body = gzip.compress(request.body) 10 request.data = gzipped_body 11 12 # registers the custom handler 13 event_system.register('before-sign.cloudwatch.PutMetricData', 14 gzip_request_body) 15 16 17 import boto3 import gzip cw_client = boto3.client('cloudwatch') event_system = cw_client.meta.events # Gzip handler def gzip_request_body(request, **kwargs): request.headers.add_header('Content-Encoding', 'gzip') gzipped_body = gzip.compress(request.body) request.data = gzipped_body # registers the custom handler event_system.register('before-sign.cloudwatch.PutMetricData', gzip_request_body) cw_client.put_metric_data(...) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 loige 23
  • 53. loige Other potential use cases Log data before/after it is sent to AWS Add additional headers to AWS requests (tracing) Additional input validation (your custom rules) Payload enrichment (e.g. make sure certain tags exist) 25
  • 54. loige What if you don't use Python? Customizing the AWS SDK for Go V2 Client Requests Introducing Middleware Stack in Modular AWS SDK for JavaScript Handlers and Middleware in the AWS SDK for PHP Version 3 26
  • 55. loige What did we learn? Always have alarms for your lambdas! (have you checked already? 😉) You can use Gzip compression to send big payloads to AWS Boto3 is extensible through its event system! SLIC Watch 27
  • 56. loige Do you think boto3 should make it easier to send gzipped payloads? 👍UPVOTE this issue: github.com/boto/botocore/issues/2425 28
  • 57. loige Do you want more details? loige.link/gzip-boto3-article 29
  • 58. Cover picturea by on Thanks doggie by Stefanie Shank Moritz Mentges Unsplash loige nodejsdp.link loige.link/gzip-boto3 30