Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 4a98793

Browse files
SQS: Complete implementation and testing of AWS::SQS:* CloudFormation resource providers.
1 parent b613fb9 commit 4a98793

29 files changed

+1445
-156
lines changed

localstack-core/localstack/services/cloudformation/provider_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ def resource_tags_to_remove_or_update(
297297

298298
# LocalStack specific utilities
299299
def get_schema_path(file_path: Path) -> dict:
300-
file_name_base = file_path.name.removesuffix(".py").removesuffix(".py.enc")
300+
file_name_base = (
301+
file_path.name.removesuffix("_base.py").removesuffix(".py").removesuffix(".py.enc")
302+
)
301303
with Path(file_path).parent.joinpath(f"{file_name_base}.schema.json").open() as fd:
302304
return json.load(fd)

localstack-core/localstack/services/sqs/resource_providers/aws_sqs_queue.py

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,17 @@
22
from __future__ import annotations
33

44
import json
5-
from pathlib import Path
6-
from typing import TypedDict
75

86
import localstack.services.cloudformation.provider_utils as util
97
from localstack.services.cloudformation.resource_provider import (
108
OperationStatus,
119
ProgressEvent,
12-
ResourceProvider,
1310
ResourceRequest,
1411
)
15-
16-
17-
class SQSQueueProperties(TypedDict):
18-
Arn: str | None
19-
ContentBasedDeduplication: bool | None
20-
DeduplicationScope: str | None
21-
DelaySeconds: int | None
22-
FifoQueue: bool | None
23-
FifoThroughputLimit: str | None
24-
KmsDataKeyReusePeriodSeconds: int | None
25-
KmsMasterKeyId: str | None
26-
MaximumMessageSize: int | None
27-
MessageRetentionPeriod: int | None
28-
QueueName: str | None
29-
QueueUrl: str | None
30-
ReceiveMessageWaitTimeSeconds: int | None
31-
RedriveAllowPolicy: dict | str | None
32-
RedrivePolicy: dict | str | None
33-
SqsManagedSseEnabled: bool | None
34-
Tags: list[Tag] | None
35-
VisibilityTimeout: int | None
36-
37-
38-
class Tag(TypedDict):
39-
Key: str | None
40-
Value: str | None
41-
42-
43-
REPEATED_INVOCATION = "repeated_invocation"
12+
from localstack.services.sqs.resource_providers.generated.aws_sqs_queue_base import (
13+
SQSQueueProperties,
14+
SQSQueueProviderBase,
15+
)
4416

4517
_queue_attribute_list = [
4618
"ContentBasedDeduplication",
@@ -60,10 +32,7 @@ class Tag(TypedDict):
6032
]
6133

6234

63-
class SQSQueueProvider(ResourceProvider[SQSQueueProperties]):
64-
TYPE = "AWS::SQS::Queue" # Autogenerated. Don't change
65-
SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change
66-
35+
class SQSQueueProvider(SQSQueueProviderBase):
6736
# Values used when a property is removed from a template and needs to be set to its default.
6837
# If AWS changes their defaults in the future, our parity tests should break.
6938
DEFAULT_ATTRIBUTE_VALUES = {
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# LocalStack Resource Provider Scaffolding v2
2+
import json
3+
4+
from localstack.services.cloudformation.resource_provider import (
5+
OperationStatus,
6+
ProgressEvent,
7+
ResourceRequest,
8+
)
9+
from localstack.services.sqs.resource_providers.generated.aws_sqs_queueinlinepolicy_base import (
10+
SQSQueueInlinePolicyProperties,
11+
SQSQueueInlinePolicyProviderBase,
12+
)
13+
14+
15+
class SQSQueueInlinePolicyProvider(SQSQueueInlinePolicyProviderBase):
16+
def create(
17+
self,
18+
request: ResourceRequest[SQSQueueInlinePolicyProperties],
19+
) -> ProgressEvent[SQSQueueInlinePolicyProperties]:
20+
model = request.desired_state
21+
sqs = request.aws_client_factory.sqs
22+
23+
queue = model.get("Queue")
24+
policy = model.get("PolicyDocument")
25+
sqs.set_queue_attributes(QueueUrl=queue, Attributes={"Policy": json.dumps(policy)})
26+
27+
return ProgressEvent(
28+
status=OperationStatus.SUCCESS,
29+
resource_model=model,
30+
custom_context=request.custom_context,
31+
)
32+
33+
def read(
34+
self,
35+
request: ResourceRequest[SQSQueueInlinePolicyProperties],
36+
) -> ProgressEvent[SQSQueueInlinePolicyProperties]:
37+
raise NotImplementedError
38+
39+
def delete(
40+
self,
41+
request: ResourceRequest[SQSQueueInlinePolicyProperties],
42+
) -> ProgressEvent[SQSQueueInlinePolicyProperties]:
43+
model = request.desired_state
44+
sqs = request.aws_client_factory.sqs
45+
46+
queue = model.get("Queue")
47+
sqs.set_queue_attributes(QueueUrl=queue, Attributes={"Policy": ""})
48+
49+
return ProgressEvent(status=OperationStatus.SUCCESS, resource_model={})
50+
51+
def update(
52+
self,
53+
request: ResourceRequest[SQSQueueInlinePolicyProperties],
54+
) -> ProgressEvent[SQSQueueInlinePolicyProperties]:
55+
model = request.desired_state
56+
sqs = request.aws_client_factory.sqs
57+
58+
queue = model.get("Queue")
59+
policy = model.get("PolicyDocument")
60+
sqs.set_queue_attributes(QueueUrl=queue, Attributes={"Policy": json.dumps(policy)})
61+
62+
return ProgressEvent(
63+
status=OperationStatus.SUCCESS,
64+
resource_model=model,
65+
custom_context=request.custom_context,
66+
)
67+
68+
def list(
69+
self,
70+
request: ResourceRequest[SQSQueueInlinePolicyProperties],
71+
) -> ProgressEvent[SQSQueueInlinePolicyProperties]:
72+
"""
73+
List available resources of this type
74+
75+
"""
76+
raise NotImplementedError

localstack-core/localstack/services/sqs/resource_providers/aws_sqs_queuepolicy.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
from __future__ import annotations
33

44
import json
5-
from pathlib import Path
65
from typing import TypedDict
76

87
import localstack.services.cloudformation.provider_utils as util
98
from localstack.services.cloudformation.resource_provider import (
109
OperationStatus,
1110
ProgressEvent,
12-
ResourceProvider,
1311
ResourceRequest,
1412
)
13+
from localstack.services.sqs.resource_providers.generated.aws_sqs_queuepolicy_base import (
14+
SQSQueuePolicyProviderBase,
15+
)
1516

1617

1718
class SQSQueuePolicyProperties(TypedDict):
@@ -23,10 +24,7 @@ class SQSQueuePolicyProperties(TypedDict):
2324
REPEATED_INVOCATION = "repeated_invocation"
2425

2526

26-
class SQSQueuePolicyProvider(ResourceProvider[SQSQueuePolicyProperties]):
27-
TYPE = "AWS::SQS::QueuePolicy" # Autogenerated. Don't change
28-
SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change
29-
27+
class SQSQueuePolicyProvider(SQSQueuePolicyProviderBase):
3028
def create(
3129
self,
3230
request: ResourceRequest[SQSQueuePolicyProperties],
@@ -100,13 +98,32 @@ def update(
10098
"""
10199
model = request.desired_state
102100
sqs = request.aws_client_factory.sqs
103-
for queue in model.get("Queues", []):
101+
102+
# handle new/updated queues
103+
desired_queues = model.get("Queues", [])
104+
for queue in desired_queues:
104105
policy = json.dumps(model["PolicyDocument"])
105106
sqs.set_queue_attributes(QueueUrl=queue, Attributes={"Policy": policy})
106107

108+
# handle queues no longer in the desired state
109+
previous_queues = request.previous_state.get("Queues", [])
110+
outdated_queues = set(previous_queues) - set(desired_queues)
111+
for queue in outdated_queues:
112+
sqs.set_queue_attributes(QueueUrl=queue, Attributes={"Policy": ""})
113+
107114
model["Id"] = request.previous_state["Id"]
108115

109116
return ProgressEvent(
110117
status=OperationStatus.SUCCESS,
111118
resource_model=model,
112119
)
120+
121+
def list(
122+
self,
123+
request: ResourceRequest[SQSQueuePolicyProperties],
124+
) -> ProgressEvent[SQSQueuePolicyProperties]:
125+
"""
126+
List available resources of this type
127+
128+
"""
129+
raise NotImplementedError

localstack-core/localstack/services/sqs/resource_providers/aws_sqs_queuepolicy.schema.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

localstack-core/localstack/services/sqs/resource_providers/aws_sqs_queue.schema.json renamed to localstack-core/localstack/services/sqs/resource_providers/generated/aws_sqs_queue.schema.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@
123123
"taggable": true,
124124
"tagOnCreate": true,
125125
"tagUpdatable": true,
126-
"cloudFormationSystemTags": true,
127-
"tagProperty": "/properties/Tags"
126+
"cloudFormationSystemTags": false,
127+
"tagProperty": "/properties/Tags",
128+
"permissions": [
129+
"sqs:TagQueue",
130+
"sqs:UntagQueue",
131+
"sqs:ListQueueTags"
132+
]
128133
},
129134
"handlers": {
130135
"create": {

0 commit comments

Comments
 (0)