A few of the sample AWS Lambda function codes for common use-cases with Amazon EC2, AWS Lambda, API Gateway & Amazon SNS using Python runtime.
-
Delete EBS volumes using a snapshot and its status - delete_volumes_by_snapshot.py
-
Delete EBS volumes by snapshot - delete_volumes_by_snapshot.py
-
Describe all AMIs for your account across all regions - describe_ami.py
-
Describe EC2's metadata in a region - Associated subnets, Instance ID & NACL ID for a target VPC - describe_ec2_securitygroup.py
-
Start/Stop EC2 instances using CloudWatch Event Trigger - start_stop_ec2_instances_with_cloudwatch_event.py
-
Get all async configuration (Max retry attempts, max event age, destinations) across all regions - async_config_dashboard.py
-
Delete orphaned Event Source Mappings - clean_orphaned_event_source_mappings.py
-
Extract Lambda code from the entire deployment package - extract_deployment_package_without_layers
-
Check Async queue congestions and delays in processing async events - get_async_invoke_delay.py
-
Get underlying Lambda's CPU hardware, /tmp storage, os-release and it's contents - get_cpu_info.py
-
Test HTTP connection for your Lambda function inside VPC - http_connection_test.py
-
List code storage for all Lambda functions in a region - lambda_code_size_all_functions.py
-
List code storage for a function including all attached layers - lambda_code_size_including_layers.py
-
List all ENIs created by Lambda functions(s) - lambda_created_enis.py
-
Get Lambda dashboard metrics across all regions - lambda_dashboard.py
-
List Lambda function version(s) using an ENI - lambda_hyperplane_eni_checker.py
-
Create "Memory Used" Metrics for your Lambda functions - lambda_memory_plot.py
-
Get all functions using reserved or provisional concurrency in a region - list_concurrency_functions.py
-
List Lambda functions using a runtime - list_functions_by_a_runtime
-
List all Lambda layers and it's info - list_layer_info.py
-
Use Python modules from layers over the deployment package - use_modules_from_layers
-
Lambda X-Ray examples - x_ray_sample.py
-
List all subscriptions tied to a topic in an account - list_account_topic_subscriptions.py
-
Programmatically create subscription filters for SNS - set_subscription_filters.py
-
Programmatically set SenderID while sending SMS text messages - sender_id.py
-
Programmatically set max price while sending SMS text messages - set_max_price.py
-
Get SMS month to date spend in USD - sms_month_to_date_spent_usd.py
-
SMS Dashboard - sms_dashboard.py
-
Send SMS with a custom originating number - sms_with_custom_originating_number
- Upload Binary Image to S3 using a POST request - upload_image_to_s3.py
- Please take a look at the individual .md files for additional information.
-
π° Something broken? Open an issue with a few sample inputs where it breaks. Screenshots help!
-
More additional services/use-cases, open a new issue
This is an iterative repository, I'll keep adding more sample codes for more use cases as I come across them. I had initially created all sample scripts using Python3.6
runtime which is now deprecated. Moving forward, I'll use the latest supported Python runtime in Lambda.
- Fork repo
- Set runtime as
Python3
(Python3.7
preferred) - Send your awesome π Pull Request with code/.md changes
- Follow Python's PEP8 coding standards.
- Commit repo using the Seven Rules
- Your PR gets merged β and a shout-outπ’
$ tree
.
βββ CODE_OF_CONDUCT.md
βββ LICENSE
βββ README.md
βββ api-gateway-samples
βΒ Β βββ upload_image_to_s3
βΒ Β βββ README.md
βΒ Β βββ template.yml
βΒ Β βββ upload_image_to_s3.py
βββ ec2-samples
βΒ Β βββ delete_older_snapshots
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ delete_older_snapshots.py
βΒ Β βββ delete_volumes_by_snapshot
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ delete_volumes_by_snapshot.py
βΒ Β βββ describe_ami
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ describe_ami.py
βΒ Β βββ describe_ec2_securitygroup
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ describe_ec2_securitygroup.py
βΒ Β βββ start_stop_ec2_instances_with_cloudwatch_event
βΒ Β βββ README.md
βΒ Β βββ start_stop_ec2_instances_with_cloudwatch_event.py
βββ lambda-layer
βΒ Β βββ README.md
βΒ Β βββ boto3.zip
βΒ Β βββ pandasnumpy.zip
βΒ Β βββ prettyTable.zip
βΒ Β βββ psycopg2.zip
βΒ Β βββ python38+
βΒ Β βΒ Β βββ boto3_python38+.zip
βΒ Β βΒ Β βββ numpy_pandas_scipy_python38+.zip
βΒ Β βΒ Β βββ requests_python38+.zip
βΒ Β βΒ Β βββ urllib3_python38+.zip
βΒ Β βββ requests.zip
βΒ Β βββ urllib3.zip
βΒ Β βββ x-ray.zip
βββ lambda-samples
βΒ Β βββ async_config_dashboard
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ async_config_dashboard.py
βΒ Β βββ clean_orphaned_event_source_mappings
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ clean_orphaned_event_source_mappings.py
βΒ Β βββ extract_deployment_package_without_layers
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ extract_deployment_package_without_layers.py
βΒ Β βββ get_async_invoke_delay
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ get_async_invoke_delay.py
βΒ Β βββ get_cpu_info
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ get_cpu_info.py
βΒ Β βββ http_connection_test
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ http_connection_test.py
βΒ Β βββ lambda_code_size_all_functions
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ lambda_code_size_all_functions.py
βΒ Β βββ lambda_code_size_including_layers
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ lambda_code_size_including_layers.py
βΒ Β βββ lambda_created_enis
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ lambda_created_enis.py
βΒ Β βββ lambda_dashboard
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ lambda_dashboard.py
βΒ Β βββ lambda_hyperplane_eni_checker
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ lambda_hyperplane_eni_checker.py
βΒ Β βββ lambda_memory_plot
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ lambda_memory_plot.py
βΒ Β βββ list_concurrency_functions
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ list_concurrency_functions.py
βΒ Β βββ list_functions_by_a_runtime
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ list_functions_by_a_runtime.py
βΒ Β βββ list_layer_info
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ list_layer_info.py
βΒ Β βββ use_modules_from_layers
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ use_modules_from_layers.py
βΒ Β βββ x_ray_sample
βΒ Β βββ README.md
βΒ Β βββ x_ray_sample.py
βββ sns-samples
βΒ Β βββ list_account_topic_subscriptions
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ list_account_topic_subscriptions.py
βΒ Β βββ sender_id
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ sender_id.py
βΒ Β βββ set_max_price_sms
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ set_max_price_sms.py
βΒ Β βββ set_subscription_filters
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ set_subscription_filters.py
βΒ Β βββ sms_dashboard
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ sms_dashboard.py
βΒ Β βββ sms_month_to_date_spent_usd
βΒ Β βΒ Β βββ README.md
βΒ Β βΒ Β βββ sms_month_to_date_spent_usd.py
βΒ Β βββ sms_with_custom_originating_number
βΒ Β βββ README.md
βΒ Β βββ sms_with_custom_originating_number.py
βββ tmp
βββ images
βββ AWSLambdaAsyncDelayCloudWatchInsights.png
βββ AWSLambdaCloudWatchAsyncDelay.png
βββ AWSLambdaCloudWatchMetric.png
βββ AWSLambdaX-Ray.PNG