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

2

6

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.

Cleon answered 23/11, 2020 at 9:32 Comment(2)
both awscli and boto3 installed using pip installCleon
Can you provide full example code? Also are you running this on some linux distro?Fluoridate
H
3
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

Housewares answered 21/1, 2021 at 12:6 Comment(0)
C
0

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>)

Charcot answered 26/7, 2022 at 20:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.