Skip to content

Snippet of code to sign aiohttp requests for invoking AWS Lambda functions

License

Notifications You must be signed in to change notification settings

byrro/aws-lambda-signed-aiohttp-requests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AWS Lambda signed aiohttp requests

What is this

Snippet of Python code to sign aiohttp requests using SigV4 for invoking AWS Lambda functions concurrently.

Why

This code will make your life a lot easier when you need to send multiple Lambda invocation requests at once, either synchronously or asynchronously. It uses the aiohttp library to send requests concurrently and automatically signs requests using your IAM credentials.

Both boto3 invoke and invoke_async APIs implement blocking code. Meaning: if you need to send multiple invocations at once, your Python code will send the first one, wait for it to respond, then send the second, and so on.

How to

  1. Import the aiohttp_signed_lambda.py snippet into your project.
  2. Call the invoke_all function with the following arguments:
    • requests [List]: a list of Dictionaries containing invocation arguments
    • region [String]: the AWS region where the invoked Lambda functions reside

Example

from signed_aiohttp_lambda import invoke_all


INVOCATION_ARGS = [
    {
        'function_name': 'my-lambda-function',
        'payload': {
            'hello': 'world',
        },
        'invocation_type': 'RequestResponse',  # Synchronous invocation
        'region': 'us-east-2',
    },
    {
        'function_name': 'another-lambda',
        'payload': {
            'task': 'execute xyz',
            'args': 123,
        },
        'invocation_type': 'Event',  # Asynchronous invocation
        'region': 'eu-west-1',
    },
    {
        'function_name': 'yet-another-lambda',
        'payload': {
            'foo': 'bar',
        },
        'invocation_type': 'DryRun',  # Validate parameter values & permissions
    },
]

# The region argument will be used for request invocations that do not
# specify one
responses = invoke_all(requests=INVOCATION_ARGS, region='us-east-1')

About

Snippet of code to sign aiohttp requests for invoking AWS Lambda functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages