Created
June 9, 2017 07:12
-
-
Save drumadrian/3f92567b6fba3d15e453306418000194 to your computer and use it in GitHub Desktop.
AWS Lambda and AWS API Gateway circular request Storm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################################## | |
# Purpose: This function is triggerd to start a circular Lambda API Gateway storm | |
# | |
# Author: Adrian Drummond & Ben Harloe | |
# | |
# Date: June 8, 2017 (initial creation) | |
# ? (updated) | |
# | |
# Triggered by: A manual Lambda function execution | |
# | |
# Summary: This Lambda function hits an API which hits a backend Lambda function....and | |
# the storm or repeating starts. :-) | |
################################################################################################## | |
import boto3 | |
import subprocess | |
import os | |
# ToDo: | |
# 1) add DEBUG flag for print messages | |
# 2) implement a counter using a seperate endpoint and DynamodB | |
# 3) implement a Elasticache cluster to speed up queries to DynamoDB | |
####### Global debugging flag ####### | |
DEBUG = True | |
def lambda_handler(event, context): | |
print 'Running lambda_handler' | |
if event != "local": | |
url = os.environ['url'] | |
print "url=" | |
print url | |
API_address = url | |
else: | |
API_address = "" | |
command = "curl -I " + API_address | |
result = subprocess.call(command, shell=True) | |
return result | |
# For locally running this function | |
if __name__ == '__main__': | |
print 'Running Locally?....' | |
test_event="local" | |
context = "not yet setup for local testing" | |
lambda_handler(test_event,context) | |
else: | |
print '__name__ !=__main__ So this is probably running in AWS' | |
print 'ALERT: You should NOT be seeing this Alert!!' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment