Giter VIP home page Giter VIP logo

aws-lambda-code-samples's Introduction

AWS Lambda sample codes Language grade: Python HitCount

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.

EC2

  1. Delete EBS volumes using a snapshot and its status - delete_volumes_by_snapshot.py

  2. Delete EBS volumes by snapshot - delete_volumes_by_snapshot.py

  3. Describe all AMIs for your account across all regions - describe_ami.py

  4. Describe EC2's metadata in a region - Associated subnets, Instance ID & NACL ID for a target VPC - describe_ec2_securitygroup.py

  5. Start/Stop EC2 instances using CloudWatch Event Trigger - start_stop_ec2_instances_with_cloudwatch_event.py

Lambda

  1. Get all async configuration (Max retry attempts, max event age, destinations) across all regions - async_config_dashboard.py

  2. Delete orphaned Event Source Mappings - clean_orphaned_event_source_mappings.py

  3. Extract Lambda code from entire deployment package - extract_deployment_package_without_layers

  4. Check Async queue congestions and delays in processing async events - get_async_invoke_delay.py

  5. Get underlying Lambda's CPU hardware, /tmp storage, os-release and it's contents - get_cpu_info.py

  6. Test HTTP connection for your Lambda function inside VPC - http_connection_test.py

  7. List code storage for all Lambda functions in a region - lambda_code_size_all_functions.py

  8. List code storage for a function including all attached layers - lambda_code_size_including_layers.py

  9. List all ENIs created by Lambda functions(s) - lambda_created_enis.py

  10. Get Lambda dashboard metrics across all regions - lambda_dashboard.py

  11. List Lambda function version(s) using an ENI - lambda_hyperplane_eni_checker.py

  12. Create "Memory Used" Metrics for your Lambda functions - lambda_memory_plot.py

  13. Get all functions using reserved or provisional concurrency in a region - list_concurrency_functions.py

  14. List Lambda functions using a runtime - list_functions_by_a_runtime

  15. List all Lambda layers and it's info - list_layer_info.py

  16. Use python modules from layers over deployment package - use_modules_from_layers

  17. Lambda X-Ray examples - x_ray_sample.py

SNS

  1. List all subscriptions tied to a topic in an account - list_account_topic_subscriptions.py

  2. Programmatically create subscription filters for SNS - set_subscription_filters.py

  3. Programmatically set SenderID while sending SMS text messages - sender_id.py

  4. Programmatically set max price while sending SMS text messages - set_max_price.py

  5. Get SMS month to date spend in USD - sms_month_to_date_spent_usd.py

  6. SMS Dashboard - sms_dashboard.py

  7. Send SMS with custom originating number - sms_with_custom_originating_number

API Gateway

  1. Upload Binary Image to S3 using a POST request - upload_image_to_s3.py

Additional Information

  • Refer to the individual .md files for additional information.

Built with

Missing Info / Bugs

  • ๐Ÿ˜ฐ Something broken? Open an issue with a few sample inputs where it breaks. Screenshots help!

  • More additional services/use-cases, open a new issue

Contributing

This is an iterative repository, I'll keep adding more sample codes for more use-cases as I come across them. I have tested all scripts using Python3.6 runtime inside Lambda under us-west-2 region, and most of this should work for all Python3 runtime.

  • Fork repo
  • Set runtime as Python3 (Python3.7 preferred)
  • Send your awesome ๐Ÿ™Œ Pull Request with code/.md changes
  • Your PR gets merged โœ… and a shout out ๐Ÿ“ข

Looking for CLI samples?

Repo structure:

$ 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

aws-lambda-code-samples's People

Contributors

imgbotapp avatar shreyasgaonkar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

aws-lambda-code-samples's Issues

[Feature Request] Using imagemagik to process thumbnail of S3 images

Is your feature request related to a problem? Please describe.

  • Using Lambda with imagemagik (as a layer?) to create thumbnail images from S3 and store it back to s3 in a different folder

Describe the solution you'd like
S3

Describe alternatives you've considered
Use of layer rather than deployment package

Additional context
N/A

[Feature Request] Clean orphaned event source mappings

Is your feature request related to a problem? Please describe.

  • When dealing with stream based event source mappings, the triggers aren't cleaned when the function is deleted.

Describe the solution you'd like

  • Script that will clean all the orphaned event sources

Describe alternatives you've considered
N/A

Additional context

  • Can be replicated for DDB trigger

Download lambda functions source code without it's layers

Describe the solution you'd like
A script that could maybe download the lambda function's source code only?

Describe alternatives you've considered
I've written one, but the API only allows for downloading the whole lambda function and I can't separate layers from it.

List functions and versions by runtimes

Is your feature request related to a problem? Please describe.
This is helpful for any runtime nearing the deprecation cycle and you want to identify the functions to be updated

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.