Last active
September 19, 2018 03:09
-
-
Save cfclrk/325c3efa2080696c6baa345bbb29aa4d to your computer and use it in GitHub Desktop.
Asyncio botocore waiter
This file contains hidden or 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 botocore.session | |
import functools | |
cloudformation_template = """ | |
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Resources": { | |
"queue1": { | |
"Type": "AWS::SQS::Queue", | |
"Properties": { | |
"QueueName": "my-queue" | |
} | |
} | |
} | |
} | |
""" | |
loop = asyncio.get_event_loop() | |
session = botocore.session.get_session() | |
cloudformation_client = session.create_client('cloudformation', region_name='us-east-1') | |
async def create_stack(): | |
print('creating cloudformation stack') | |
await loop.run_in_executor( | |
None, | |
functools.partial( | |
cloudformation_client.create_stack, StackName='my-stack', TemplateBody=cloudformation_template)) | |
async def wait_for_stack_create_complete(): | |
print('waiting for cloudformation stack creation to complete') | |
waiter = cloudformation_client.get_waiter('stack_create_complete') | |
await loop.run_in_executor(None, functools.partial(waiter.wait, StackName='my-stack')) | |
loop.run_until_complete(create_stack()) | |
loop.run_until_complete(wait_for_stack_create_complete()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment