Skip to content

Instantly share code, notes, and snippets.

@russau
Last active August 22, 2023 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save russau/2407c8a147967b7d3c0083207cab2d44 to your computer and use it in GitHub Desktop.
Save russau/2407c8a147967b7d3c0083207cab2d44 to your computer and use it in GitHub Desktop.
Async aioboto3 from lambda
import asyncio
import aioboto3
session = aioboto3.Session()
async def main():
async with session.client("ec2") as ec2:
tasks = await asyncio.gather(
ec2.describe_regions(),
ec2.describe_instances()
)
return len(tasks[0]["Regions"]), len(tasks[1]["Reservations"])
def lambda_handler(event, context):
return asyncio.run(main())
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Timeout: 30
MemorySize: 128
Resources:
DocumentLambdaFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: DocumentLambdaFunction
CodeUri: DocumentLambdaFunction/
Handler: app.lambda_handler
Runtime: python3.9
Policies:
- EC2DescribePolicy: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment