This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add resource provider for AWS::SQS::QueuePolicy #8989
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
localstack/services/sqs/resource_providers/aws_sqs_queuepolicy.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # LocalStack Resource Provider Scaffolding v2 | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from pathlib import Path | ||
| from typing import Optional, Type, TypedDict | ||
|
|
||
| import localstack.services.cloudformation.provider_utils as util | ||
| from localstack.services.cloudformation.resource_provider import ( | ||
| CloudFormationResourceProviderPlugin, | ||
| OperationStatus, | ||
| ProgressEvent, | ||
| ResourceProvider, | ||
| ResourceRequest, | ||
| ) | ||
|
|
||
|
|
||
| class SQSQueuePolicyProperties(TypedDict): | ||
| PolicyDocument: Optional[dict] | ||
| Queues: Optional[list[str]] | ||
| Id: Optional[str] | ||
|
|
||
|
|
||
| REPEATED_INVOCATION = "repeated_invocation" | ||
|
|
||
|
|
||
| class SQSQueuePolicyProvider(ResourceProvider[SQSQueuePolicyProperties]): | ||
|
|
||
| TYPE = "AWS::SQS::QueuePolicy" # Autogenerated. Don't change | ||
| SCHEMA = util.get_schema_path(Path(__file__)) # Autogenerated. Don't change | ||
|
|
||
| def create( | ||
| self, | ||
| request: ResourceRequest[SQSQueuePolicyProperties], | ||
| ) -> ProgressEvent[SQSQueuePolicyProperties]: | ||
| """ | ||
| Create a new resource. | ||
|
|
||
| Primary identifier fields: | ||
| - /properties/Id | ||
|
|
||
| Required properties: | ||
| - PolicyDocument | ||
| - Queues | ||
|
|
||
| Read-only properties: | ||
| - /properties/Id | ||
|
|
||
| """ | ||
| model = request.desired_state | ||
| sqs = request.aws_client_factory.sqs | ||
| for queue in model.get("Queues", []): | ||
| policy = json.dumps(model["PolicyDocument"]) | ||
| sqs.set_queue_attributes(QueueUrl=queue, Attributes={"Policy": policy}) | ||
|
|
||
| physical_resource_id = util.generate_default_name( | ||
| stack_name=request.stack_name, logical_resource_id=request.logical_resource_id | ||
| ) | ||
| model["Id"] = physical_resource_id | ||
|
|
||
| return ProgressEvent( | ||
| status=OperationStatus.SUCCESS, | ||
| resource_model=model, | ||
| custom_context=request.custom_context, | ||
| ) | ||
|
|
||
| def read( | ||
| self, | ||
| request: ResourceRequest[SQSQueuePolicyProperties], | ||
| ) -> ProgressEvent[SQSQueuePolicyProperties]: | ||
| """ | ||
| Fetch resource information | ||
| """ | ||
| raise NotImplementedError | ||
|
|
||
| def delete( | ||
| self, | ||
| request: ResourceRequest[SQSQueuePolicyProperties], | ||
| ) -> ProgressEvent[SQSQueuePolicyProperties]: | ||
| """ | ||
| Delete a resource | ||
| """ | ||
| sqs = request.aws_client_factory.sqs | ||
| for queue in request.previous_state["Queues"]: | ||
| try: | ||
| sqs.set_queue_attributes(QueueUrl=queue, Attributes={"Policy": ""}) | ||
|
|
||
| except sqs.exceptions.ClientError as err: | ||
| if "AWS.SimpleQueueService.NonExistentQueue" != err.response["Error"]["Code"]: | ||
| return ProgressEvent(status=OperationStatus.FAILED, resource_model={}) | ||
|
|
||
| return ProgressEvent( | ||
| status=OperationStatus.SUCCESS, | ||
| resource_model={}, | ||
| ) | ||
|
|
||
| def update( | ||
| self, | ||
| request: ResourceRequest[SQSQueuePolicyProperties], | ||
| ) -> ProgressEvent[SQSQueuePolicyProperties]: | ||
| """ | ||
| Update a resource | ||
| """ | ||
| raise NotImplementedError | ||
|
|
||
|
|
||
| class SQSQueuePolicyProviderPlugin(CloudFormationResourceProviderPlugin): | ||
| name = "AWS::SQS::QueuePolicy" | ||
|
|
||
| def __init__(self): | ||
| self.factory: Optional[Type[ResourceProvider]] = None | ||
|
|
||
| def load(self): | ||
| self.factory = SQSQueuePolicyProvider | ||
30 changes: 30 additions & 0 deletions
30
localstack/services/sqs/resource_providers/aws_sqs_queuepolicy.schema.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| { | ||
| "typeName": "AWS::SQS::QueuePolicy", | ||
| "description": "Resource Type definition for AWS::SQS::QueuePolicy", | ||
| "additionalProperties": false, | ||
| "properties": { | ||
| "Id": { | ||
| "type": "string" | ||
| }, | ||
| "PolicyDocument": { | ||
| "type": "object" | ||
| }, | ||
| "Queues": { | ||
| "type": "array", | ||
| "uniqueItems": false, | ||
| "items": { | ||
| "type": "string" | ||
| } | ||
| } | ||
| }, | ||
| "required": [ | ||
| "PolicyDocument", | ||
| "Queues" | ||
| ], | ||
| "primaryIdentifier": [ | ||
| "/properties/Id" | ||
| ], | ||
| "readOnlyProperties": [ | ||
| "/properties/Id" | ||
| ] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: why leave out read here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in use currently. Just aiming to migrate a few resources from their GenericBaseModel implementation to a "raw" ResourceProvider one.