terricain / aioboto3

Wrapper to use boto3 resources with the aiobotocore async backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aiboto3 with ec2

marcelo321 opened this issue · comments

  • Async AWS SDK for Python version: last version
  • Python version: python3
  • Operating System: ubuntu last version

Description

I am trying to allocate a ec2 ip but I don't know where the error is:

async def get_ip(account, region):
    try:
        async with aioboto3.client('ec2', aws_access_key_id='idhere', aws_secret_access_key=''keyhere',
                                   region_name=region) as ec2:
            addr = await ec2.allocate_address(Domain='vpc')
            print(addr)
    except Exception as ex:
        print(Exception)

I also tried:

        session = aioboto3.Session()
        async with session.resource('ec2', aws_access_key_id='idhere', aws_secret_access_key=''keyhere',
                                   region_name=region) as ec2:

I get "'ec2.ServiceResource' object has no attribute 'allocate_address'" but I don't know why.

Where can I get the documents to try do this properly? is there any way to chat about this apart from github @terrycain ?

The problem is this isn't running in my new server (which seem to have the same versions of async, python and os, but was working in the previous one). unable to find out why this isn't working now.

The same exact code works in my previous VPS. The following versions are the same in both servers:

aioboto3               8.3.0               
aiobotocore            1.2.2               
boto3                  1.16.52             
botocore               1.19.52
Python 3.8.10

So I am losing my mind trying to understand why it doesn't work here. (also other modules such as s3 and others don't work).

9.3.1 is out, I'd suggest trying with that.

import asyncio
import aioboto3

async def main():
    session = aioboto3.Session()
    async with session.client('ec2') as ec2:
        await ec2.allocate_address(Domain='vpc')

if __name__ == '__main__':
    asyncio.run(main())

This worked perfectly fine for me.