SQS - Use full URL as the physical resource ID (#4864)

This commit is contained in:
Bert Blommers 2022-02-15 22:26:36 -01:00 committed by GitHub
parent 871591f7f1
commit f49c81037b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -37,7 +37,7 @@ from .exceptions import (
InvalidAttributeValue,
)
from moto.core import ACCOUNT_ID as DEFAULT_ACCOUNT_ID
from moto.core import ACCOUNT_ID
DEFAULT_SENDER_ID = "AIDAIT2UOQQY3AUEKVGXU"
@ -262,7 +262,7 @@ class Queue(CloudFormationModel):
now = unix_time()
self.created_timestamp = now
self.queue_arn = "arn:aws:sqs:{0}:{1}:{2}".format(
self.region, DEFAULT_ACCOUNT_ID, self.name
self.region, ACCOUNT_ID, self.name
)
self.dead_letter_queue = None
@ -454,8 +454,11 @@ class Queue(CloudFormationModel):
def delete_from_cloudformation_json(
cls, resource_name, cloudformation_json, region_name
):
# ResourceName will be the full queue URL - we only need the name
# https://sqs.us-west-1.amazonaws.com/123456789012/queue_name
queue_name = resource_name.split("/")[-1]
sqs_backend = sqs_backends[region_name]
sqs_backend.delete_queue(resource_name)
sqs_backend.delete_queue(queue_name)
@property
def approximate_number_of_messages_delayed(self):
@ -471,7 +474,7 @@ class Queue(CloudFormationModel):
@property
def physical_resource_id(self):
return self.name
return f"https://sqs.{self.region}.amazonaws.com/{ACCOUNT_ID}/{self.name}"
@property
def attributes(self):
@ -505,7 +508,7 @@ class Queue(CloudFormationModel):
def url(self, request_url):
return "{0}://{1}/{2}/{3}".format(
request_url.scheme, request_url.netloc, DEFAULT_ACCOUNT_ID, self.name
request_url.scheme, request_url.netloc, ACCOUNT_ID, self.name
)
@property

View File

@ -62,7 +62,7 @@ def test_describe_stack_subresources():
for s in stack.resource_summaries.all():
s.resource_type.should.equal("AWS::SQS::Queue")
s.logical_id.should.equal("QueueGroup")
s.physical_resource_id.should.equal(q_name)
s.physical_resource_id.should.contain(f"/{q_name}")
@mock_sqs
@ -83,7 +83,8 @@ def test_list_stack_resources():
queue.should.have.key("ResourceType").equal("AWS::SQS::Queue")
queue.should.have.key("LogicalResourceId").should.equal("QueueGroup")
queue.should.have.key("PhysicalResourceId").should.equal(q_name)
expected_url = f"https://sqs.us-east-1.amazonaws.com/{ACCOUNT_ID}/{q_name}"
queue.should.have.key("PhysicalResourceId").should.equal(expected_url)
@mock_sqs
@ -96,7 +97,7 @@ def test_create_from_cloudformation_json_with_tags():
cf.create_stack(StackName=stack_name, TemplateBody=sqs_template_with_tags)
response = cf.describe_stack_resources(StackName=stack_name)
q_name = response["StackResources"][0]["PhysicalResourceId"]
q_name = response["StackResources"][0]["PhysicalResourceId"].split("/")[-1]
all_urls = client.list_queues(QueueNamePrefix=q_name)["QueueUrls"]
queue_url = [url for url in all_urls if url.endswith(q_name)][0]