What all changes has to be done while using a function which was using boto2 earlier and how has to be changes to boto3 below is one such function example which is on boto2 and it needs to be changed to boto3
def aws(serviceName, module=boto):
conn = connections.get(serviceName)
if conn is None:
service = getattr(module, serviceName)
conn = service.connect_to_region(region)
connections[serviceName] = conn
return conn
That code doesn't seem to be doing much. It is simply connecting to an AWS service.
The boto3 equivalent is probably:
The region can be defined in the standard
.aws/config
file, or as:I recently converted some code from
boto
toboto3
and every line pretty much needed changing. The result, however, was a lot cleaner.It is also worth trying to understand the difference between:
boto3
client: Makes normal API calls to AWSboto3
resource: A higher-level set of objects that make it easier to interact with resources, rather than using standard API calls (egvpc.subnets()
vsdescribe-subnets(VPC=xxx)
)The original code block appears to be storing its information in a
connections
array (defined elsewhere) for re-use. Therefore, the equivalent code block would be: