Search code examples
pythonamazon-web-servicesurllib2boto3urllib3

boto3 add unix credentials, urllib2/3


Can we add the unix user credentials to SQS client?

Situation : I have a user in Unix system (without 'sudo'/root privileges). And this Unix user's permissions does not allow me to connect to amazonaws.com.

Can I pass the username and password of this Unix user to boto3 client (SQS) ?

OR, can we pass boto3 client receive message object in urllib2/3?

What I already tried :

import boto3

# Create SQS client
sqs = boto3.client('sqs',region_name='eu-west-1')

queue_url='https://sqs.eu-west-1.amazonaws.com/XXXX'

# Receive message from SQS queue
response = sqs.receive_message(
    QueueUrl=queue_url,
    AttributeNames=[
        'SentTimestamp'
    ],
    MaxNumberOfMessages=10,
    MessageAttributeNames=[
        'All'
    ],
    VisibilityTimeout=0,
    WaitTimeSeconds=0
)
  • I can access any URL using urllib2 to scrape it. And I am able to pass Unix credentials while doing it.

  • As a root user I am able to get messages from amazonSQS using boto3 as mentioned in the above code.


Solution

  • No. Not possible. From your code, it looks like the credentials are stored under root user's directory which cannot be accessed by an user without sudo privileges. This is a Linux issue, nothing to do with Boto3.

    Find a way to let the user access the aws credentials. Like a soft link with read permissions on the credentials file.