AttributeError: module 'botocore' has no attribute 'session' when following the boto3 quickstart

9.9k views Asked by At

I was following the boto3 quickstart instructions and I can run import boto3, but when I try to execute any basic command like db = boto3.resource('dynamodb') I get

Traceback (most recent call last):

  File "<ipython-input-144-424c27c1bae1>", line 1, in <module>
    botocore.session.get_session()

AttributeError: module 'botocore' has no attribute 'session'

The credentials and config files look good and i tried to reinstall awscli and boto3 but is not helping. I don't understand what is the issue.

2

There are 2 answers

0
Akshay kamath B On
from botocore.session import Session

session = Session()

use above code instead of using

session = botocore.session.get_session()

botocore 1.19.57 documentation https://botocore.amazonaws.com/v1/documentation/api/latest/index.html#how-do-i-update-my-code

0
Xinxing Jiang On

Not sure why this does not work.

import boto3

boto3.resource('dynamodb')

But this works.

from botocore.session import Session

session = Session()
session.create_client("ec2", aws_access_key_id=<access_key_id>, aws_secret_access_key=<secret_access_key>)