Skip to content Skip to sidebar Skip to footer

Amazon Aws Cognito And Python Boto3 To Establish Aws Connection And Upload File To Bucket

I'm trying to use the AWS cognito service to authenticate and upload a file. I have been provided my regionType, identityPool, AWS account ID, and UnAuthRole. I also know the produ

Solution 1:

This question is really invalid because the authentication was failing not on creating a session but when trying to list the buckets.

Uploading and downloading from a specific bucket works fine with the above code but not the listing of all buckets.

# Upload a new file
data = open('test.jpg', 'rb')
s3.Bucket('mybucket').put_object(Key='test.jpg', Body=data)

# S3 Object
obj = s3.Object(bucket_name='mybucket', key='test.jpg')
response = obj.get()
data = response['Body'].read()
print len(data)

Solution 2:

PhilBot, I don't know why your original code sample connects to s3 using boto (as opposed to boto3). The code connects to cognito using boto3. As of now, boto3 is stable and there's probably not much reason to use boto anymore. (Maybe when you originally posted your question, boto3 was not as stable as it is today.)

When I tried using your code to connect to kinesis with boto3, it didn't work -- I had to pass response["Credentials"]["SessionToken"] as the aws_session_token to the client() function.

Solution 3:

This is your error:

File "./test.py", line 32, in <module>
bucket = conn.get_bucket("elektradevbucket")

This is your part of the code that references the bucket:

bucket = conn.get_bucket("testbucket")
'''
s3 = boto3.resource('s3')
forbucketin s3.buckets.all():
    print(bucket.name)
s3.Bucket('testbucket')

Are you sure you are running or calling the correct script?

Best, -Iulian

Post a Comment for "Amazon Aws Cognito And Python Boto3 To Establish Aws Connection And Upload File To Bucket"