Last active
August 22, 2023 01:42
-
-
Save russau/2407c8a147967b7d3c0083207cab2d44 to your computer and use it in GitHub Desktop.
Async aioboto3 from lambda
This file contains 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
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()) | |
This file contains 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
aioboto3 |
This file contains 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
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