Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail gracefully for S3 notifications and SNS delivery logs with strict service loading #9575

Merged
merged 2 commits into from Nov 8, 2023

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Nov 7, 2023

Motivation

We would like users to have a smooth experience when disabling services:

  • for SNS, we can disable logs and still be able to publish (even if now it's opt-in and should be less of an issue)
  • for S3, we can have people set up S3 notification without having exceptions logs

Changes

Add is_api_enabled checks before calling to return early.
For example, a quick test with LocalStack started with STRICT_SERVICE_LOADING=1 and SERVICES=s3, setting up S3 notifications with an SQS queue destination:
Calls are still successful and would be even without this PR as the notifications are asynchronous (except the verification of the target).

2023-11-07T17:52:57.310  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.CreateBucket => 200
2023-11-07T17:52:57.329  WARN --- [   asgi_gw_0] l.s.s3.notifications       : Service 'sqs' is not enabled: skipping validation of the following destination: 'arn:aws:sqs:us-east-1:111111111111:queue' Please check your 'SERVICES' configuration variable.
2023-11-07T17:52:57.331  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.PutBucketNotificationConfiguration => 200
2023-11-07T17:52:57.346  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.PutBucketVersioning => 200
2023-11-07T17:52:57.372  WARN --- [   asgi_gw_0] l.s.s3.notifications       : Service 'sqs' is not enabled: skip sending notification. Please check your 'SERVICES' configuration variable.
2023-11-07T17:52:57.373  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.PutObject => 200
2023-11-07T17:52:57.385  WARN --- [   asgi_gw_0] l.s.s3.notifications       : Service 'sqs' is not enabled: skip sending notification. Please check your 'SERVICES' configuration variable.
2023-11-07T17:52:57.385  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.PutObject => 200
2023-11-07T17:52:57.398  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.GetObjectLockConfiguration => 404 (ObjectLockConfigurationNotFoundError)
2023-11-07T17:52:57.422  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.ListObjectsV2 => 200
2023-11-07T17:52:57.442  WARN --- [   asgi_gw_0] l.s.s3.notifications       : Service 'sqs' is not enabled: skip sending notification. Please check your 'SERVICES' configuration variable.
2023-11-07T17:52:57.443  WARN --- [   asgi_gw_0] l.s.s3.notifications       : Service 'sqs' is not enabled: skip sending notification. Please check your 'SERVICES' configuration variable.

This is before this PR:

2023-11-07T17:58:55.171  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.PutObject => 200
2023-11-07T17:58:55.268  INFO --- [   asgi_gw_0] localstack.request.aws     : AWS s3.PutObject => 200
2023-11-07T17:58:55.311 ERROR --- [   asgi_gw_1] l.aws.handlers.logging     : exception during call chain: Service 'sqs' is not enabled. Please check your 'SERVICES' configuration variable.
2023-11-07T17:58:55.311  INFO --- [   asgi_gw_1] l.aws.handlers.service     : Service 'sqs' is not enabled. Please check your 'SERVICES' configuration variable.
2023-11-07T17:58:55.328 ERROR --- [   asgi_gw_0] l.aws.handlers.logging     : exception during call chain: Service 'sqs' is not enabled. Please check your 'SERVICES' configuration variable.
2023-11-07T17:58:55.329  INFO --- [   asgi_gw_0] l.aws.handlers.service     : Service 'sqs' is not enabled. Please check your 'SERVICES' configuration variable.
2023-11-07T17:58:55.333 ERROR --- [     s3_ev_0] l.s.s3.notifications       : Unable to send notification for S3 bucket "test-bucket-30757f59" to SQS queue "queue"
Traceback (most recent call last):
  File "/opt/code/localstack/localstack/services/s3/notifications.py", line 508, in notify
    queue_url = arns.sqs_queue_url_for_arn(queue_arn)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/code/localstack/localstack/utils/aws/arns.py", line 389, in sqs_queue_url_for_arn
    result = sqs_client.get_queue_url(QueueName=queue_name, QueueOwnerAWSAccountId=account_id)[
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/code/localstack/.venv/lib/python3.11/site-packages/botocore/client.py", line 535, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/code/localstack/.venv/lib/python3.11/site-packages/botocore/client.py", line 980, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InternalFailure) when calling the GetQueueUrl operation: Service 'sqs' is not enabled. Please check your 'SERVICES' configuration variable.
2023-11-07T17:58:55.345 ERROR --- [     s3_ev_1] l.s.s3.notifications       : Unable to send notification for S3 bucket "test-bucket-30757f59" to SQS queue "queue"
Traceback (most recent call last):
  File "/opt/code/localstack/localstack/services/s3/notifications.py", line 508, in notify
    queue_url = arns.sqs_queue_url_for_arn(queue_arn)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/code/localstack/localstack/utils/aws/arns.py", line 389, in sqs_queue_url_for_arn
    result = sqs_client.get_queue_url(QueueName=queue_name, QueueOwnerAWSAccountId=account_id)[
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/code/localstack/.venv/lib/python3.11/site-packages/botocore/client.py", line 535, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/code/localstack/.venv/lib/python3.11/site-packages/botocore/client.py", line 980, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InternalFailure) when calling the GetQueueUrl operation: Service 'sqs' is not enabled. Please check your 'SERVICES' configuration variable.

@bentsku bentsku self-assigned this Nov 7, 2023
@bentsku bentsku added aws:s3 Amazon Simple Storage Service aws:sns Amazon Simple Notification Service semver: patch Non-breaking changes which can be included in patch releases labels Nov 7, 2023
Copy link

github-actions bot commented Nov 7, 2023

LocalStack Community integration with Pro

       2 files         2 suites   1h 8m 24s ⏱️
2 330 tests 1 753 ✔️ 577 💤 0
2 331 runs  1 753 ✔️ 578 💤 0

Results for commit 210094e.

@coveralls
Copy link

Coverage Status

coverage: 82.535% (-0.02%) from 82.552%
when pulling 210094e on s3-notif-enabled-apis-check
into b2ad9be on master.

@bentsku bentsku requested a review from steffyP November 7, 2023 19:05
@bentsku bentsku marked this pull request as ready for review November 7, 2023 19:05
Copy link
Member

@steffyP steffyP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 🎉 🚀

@bentsku bentsku merged commit ac7ee2b into master Nov 8, 2023
36 checks passed
@bentsku bentsku deleted the s3-notif-enabled-apis-check branch November 8, 2023 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:s3 Amazon Simple Storage Service aws:sns Amazon Simple Notification Service semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants