问题
I am new to AWS. I am following AWS tutorials quick start. I was following the AWS sqs code and sqs documentation.
This is the following code which I wrote
import boto3
from boto3.session import Session
session = Session(aws_access_key_id="aswe343ffsf34r3fef3f",
aws_secret_access_key="3423d23r2fwwfe232r2r",
region_name="ap-southeast-1")
sqs = session.resource("sqs")
q_client = boto3.client("sqs")
sqs.create_queue(QueueName='test-One',
Attributes = {'DelaySeconds': '5'
})
sqs.create_queue(QueueName='test-Three',
Attributes = {'DelaySeconds': '5' })
#print "The queue path is : ",queue.url
#print dict(queue.attributes)
#print " DILAY ",queue.attributes.get("DelaySeconds")
q_client.create_queue(QueueName='test-Two',Attributes = {
"DelaySeconds" : "5"
})
#q_client.delete_queue(QueueUrl = 'https://us-west-2.queue.amazonaws.com/978916941101/test')
q = q_client.list_queues()
print "QUEUE - URLS ",q.get("QueueUrls")
qList = sqs.queues.all()
for q in qList:
print q.url
The output of the above code is
(env1)rahul@ubuntu:~/rahul/PythonPractise/Boto3_Practise$ python clientTwo.py
QUEUE - URLS ['https://us-west-2.queue.amazonaws.com/978916941101/test-Two']
https://ap-southeast-1.queue.amazonaws.com/978916941101/test
https://ap-southeast-1.queue.amazonaws.com/978916941101/test-1
https://ap-southeast-1.queue.amazonaws.com/978916941101/test-One
https://ap-southeast-1.queue.amazonaws.com/978916941101/test-Three
(env1)rahul@ubuntu:~/rahul/PythonPractise/Boto3_Practise$
My question is,
why queue Client is not able to list queues created from "resource" and why resource is does not list the queues created from client.
when I do
(env1)rahul@ubuntu:~/rahul/PythonPractise/Boto3_Practise$ aws configure list
Name Value Type Location
---- ----- ---- --------
profile <not set> None None
access_key ****************ef3f shared-credentials-file
secret_key ****************2r2r shared-credentials-file
region us-west-2 config-file ~/.aws/config
Is it because of the regions ?
回答1:
You create the resource from your custom session, which has ap-southeast-1
as the region. You create the client from the boto3 default session, which you have set to us-west-2
. When you declare a region, you only have access to resources in that region.
来源:https://stackoverflow.com/questions/34014928/aws-sqs-queues-dont-list-all-queues