C2W1 Labs 2&3 - AWS Client Instantiation

This is a more high level question regarding the AWS boto3 client.

In every user-defined function in the labs, a new client is created within in the function. Is there a reason for this? In my mind it would be more efficient to instantiate the client once (say, at the beginning of the notebook) and then pass the client by reference to the functions.

If anyone has more experience with boto3 and understands why it was done this way, I’d appreciate a response.

Thanks.

Hello @PatJon
I did a little research, and it seems like you are right. If the boto3 client is constant and does not need changing, it’s more efficient to instantiate it once and reuse it whenever needed. This can be done through a global variable to avoid needing to add it as an input parameter to all the functions. For more information, you can refer to this post.

That’s what I thought. Thanks for confirming.