I am trying to implement in python a lambda edge that receives a file, evaluates it with the length of the content and if it is greater than allowed, respond to the viewer something without sending the request to the origin, otherwise it will be sent to S3. I have already implemented the part to sent to S3, but im struggling with responding to the viewer.
Asked
Active
Viewed 78 times
1 Answers
0
You can generate a custom response to the request events triggers
Sample:
import json
def lambda_handler(event, context):
if True: # Case where you want to return the response
response = {
'body': "SAMPLE RESPONSE", # For image set this to base64 encoded string
'bodyEncoding': 'text',
'status': '200',
'statusDescription': 'OK',
'headers': {
'content-type':
[
{
'key': 'Content-Type',
'value': 'text'
}
]
}
}
return response
else: # Case where you want the request to be forwarded to the origin server
return event['Records'][0]['cf']['request']
Note: There will be some limitations on response size in case of returning response for request events. They can be found on Amazon developer guide

kartheek7895
- 341
- 1
- 12