Skip to content

Conversation

@baermat
Copy link
Member

@baermat baermat commented Oct 13, 2025

Motivation

Adds SMS attributes, with the following restrictions:

  • both DeliveryStatusIAMRole and UsageReportS3Bucket have checks on AWS to ensure everything is as expected, with all the permission management headache that IAM brings. This is not yet implemented

closes PNX-84

Changes

  • add set_sms_attributes, get_sms_attributes
  • add validity checks for values passed
  • add tests to cover validity and behaviour

@baermat baermat force-pushed the sns/v2-sms-attribute-operations branch from a457285 to 9a6b3b5 Compare October 13, 2025 11:17
Copy link
Member Author

@baermat baermat left a comment

Choose a reason for hiding this comment

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

I marked some parts which I am not too sure about, I would love to hear some feedback

Comment on lines +650 to +651
def _set_sms_attribute_default(store: SnsStore) -> None:
# TODO: don't call this on every sms attribute crud api call
store.sms_attributes.setdefault("MonthlySpendLimit", "1")
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not very happy with this, but I am not sure how to properly tackle this: When the provider is loaded, MonthlySpendLimit should be set to 1. This is saved per region however. which means I cannot really deal with this with a hook like "on_after_state_loaded". I could do it for every region, but then I am creating objects in stores for all regions, which might have side effects I am not aware of. The current solution shouldn't have a huge impact, it's just not pretty

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's an acceptable solution for now, I don't think it will have have a huge cost, and it's pretty clear what it does 👍 I think this is good! nice pragmatic solution

Comment on lines 3959 to 3976
if is_aws_cloud():
LOG.warning(
"Warning: this test will permanently set values for sms attributes in this region. \n Removing is not possible, only overwriting.\n Comment the assert if you wish to proceed"
)
raise Exception("Check logs to enable this test against AWS")
Copy link
Member Author

Choose a reason for hiding this comment

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

This is also something I am not too sure about how to deal with it. The problem is thus:
Setting one of the allowed attributes sets it permanently in AWS. Afterwards, you can only override it, but not remove it (which alters get-sms-attributes calls that retrieve all attributes). I am not sure if we can simply ignore this, and if this very strict abort is what we want

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, this is a tricky situation! I think this is an acceptable solution as well, and the error message and warning is good enough. I would however switch the markers.aws to manual_setup_required instead validated , to indicate that it might not be that easy to run against AWS. It's not "purely" manual setup required, but it might warn people a bit more that it is "a special case", what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I like it, will do!

Comment on lines 4001 to 4010
@markers.aws.validated
def test_get_sms_attributes_from_unmodified_region(
self, aws_client_factory, secondary_region_name, snapshot
):
# if the secondary region is already modified, you can use SECONDARY_TEST_AWS_PROFILE and similar
# variables to change it
sns_unmodified_region = aws_client_factory(region_name=secondary_region_name).sns
response = sns_unmodified_region.get_sms_attributes()
snapshot.match("get-sms-attributes_unmodified_region", response)

Copy link
Member Author

Choose a reason for hiding this comment

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

Same problem as before, this validates that all get_sms_attributes_call return at least MonthlySpendLimit = 1, even though you never set anything in this region. However, the person executing this test may have set an attribute at some point in time in that particular region

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, I would also set manual_setup_required, and might move the test just so that it sits right besides test_set_get_sms_attributes.

we should also maybe manually assert in this test that the value is set to 1, so that people would not inadvertently update the snapshot with some non-default values?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 The manual assert might be a bit extra safe, but then again we do not want to rely on LS having correct behaviour to "correctly" cause a snapshot mismatch in such a case.

@github-actions
Copy link

github-actions bot commented Oct 13, 2025

Test Results - Preflight, Unit

22 292 tests   - 6   20 549 ✅  - 6   15m 14s ⏱️ -41s
     1 suites ±0    1 743 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 847e34d. ± Comparison against base commit b4770eb.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Oct 13, 2025

Test Results - Alternative Providers

160 tests  +6    36 ✅ +6   32s ⏱️ -2s
  1 suites ±0   124 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 847e34d. ± Comparison against base commit b4770eb.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Oct 13, 2025

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   3m 21s ⏱️ ±0s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit 847e34d. ± Comparison against base commit b4770eb.

♻️ This comment has been updated with latest results.

@baermat baermat added semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes labels Oct 13, 2025
@baermat baermat marked this pull request as ready for review October 13, 2025 11:51
@baermat baermat requested a review from bentsku as a code owner October 13, 2025 11:51
@github-actions
Copy link

github-actions bot commented Oct 13, 2025

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   59m 55s ⏱️ +17s
2 852 tests +4  2 712 ✅  - 11  131 💤 +6  9 ❌ +9 
2 854 runs  +4  2 712 ✅  - 11  133 💤 +6  9 ❌ +9 

For more details on these failures, see this check.

Results for commit 847e34d. ± Comparison against base commit b4770eb.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Oct 13, 2025

Test Results (amd64) - Integration, Bootstrap

    5 files  ±0      5 suites  ±0   1h 27m 30s ⏱️ +3s
2 876 tests +4  2 748 ✅  - 2  128 💤 +6  0 ❌ ±0 
2 882 runs  +4  2 748 ✅  - 2  134 💤 +6  0 ❌ ±0 

Results for commit 847e34d. ± Comparison against base commit b4770eb.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@bentsku bentsku 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! I like that you went with a pragmatic solution for both the default values and the testing strategy, I think this is a good workaround around the issue.

Just have some comment about the validation and the testing markers; once this is addressed we're good to merge!

Comment on lines +650 to +651
def _set_sms_attribute_default(store: SnsStore) -> None:
# TODO: don't call this on every sms attribute crud api call
store.sms_attributes.setdefault("MonthlySpendLimit", "1")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's an acceptable solution for now, I don't think it will have have a huge cost, and it's pretty clear what it does 👍 I think this is good! nice pragmatic solution

Comment on lines 642 to 647
default_send_id = attributes.get("DefaultSendID")
if default_send_id and not re.match(SMS_DEFAULT_SENDER_REGEX, default_send_id):
raise InvalidParameterException(f"{k} is not a valid attribute")
sms_type = attributes.get("DefaultSMSType")
if sms_type and sms_type not in SMS_TYPES:
raise InvalidParameterException("DefaultSMSType is invalid")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think this code should not be in the loop, as it directly accesses the attributes

raise InvalidParameterException(f"{k} is not a valid attribute")
default_send_id = attributes.get("DefaultSendID")
if default_send_id and not re.match(SMS_DEFAULT_SENDER_REGEX, default_send_id):
raise InvalidParameterException(f"{k} is not a valid attribute")
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the right error message? it seems unrelated to the k variable and only to DefaultSendID, so we might want to hardcode that value.

Right now if you were to set 2 attributes, and DefaultSendID would be the second one in the dictionary, you'd return the wrong k

Comment on lines 3959 to 3976
if is_aws_cloud():
LOG.warning(
"Warning: this test will permanently set values for sms attributes in this region. \n Removing is not possible, only overwriting.\n Comment the assert if you wish to proceed"
)
raise Exception("Check logs to enable this test against AWS")
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, this is a tricky situation! I think this is an acceptable solution as well, and the error message and warning is good enough. I would however switch the markers.aws to manual_setup_required instead validated , to indicate that it might not be that easy to run against AWS. It's not "purely" manual setup required, but it might warn people a bit more that it is "a special case", what do you think?

Comment on lines 4001 to 4010
@markers.aws.validated
def test_get_sms_attributes_from_unmodified_region(
self, aws_client_factory, secondary_region_name, snapshot
):
# if the secondary region is already modified, you can use SECONDARY_TEST_AWS_PROFILE and similar
# variables to change it
sns_unmodified_region = aws_client_factory(region_name=secondary_region_name).sns
response = sns_unmodified_region.get_sms_attributes()
snapshot.match("get-sms-attributes_unmodified_region", response)

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, I would also set manual_setup_required, and might move the test just so that it sits right besides test_set_get_sms_attributes.

we should also maybe manually assert in this test that the value is set to 1, so that people would not inadvertently update the snapshot with some non-default values?

@bentsku bentsku added the aws:sns Amazon Simple Notification Service label Oct 14, 2025
@baermat baermat requested a review from bentsku October 15, 2025 14:19
Copy link
Contributor

@bentsku bentsku left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for addressing the comments, this looks good! Nice work 💯

Base automatically changed from sns/v2-apply-subscribe-changes to main October 15, 2025 16:17
@baermat baermat force-pushed the sns/v2-sms-attribute-operations branch from 847e34d to 3e21dff Compare October 15, 2025 17:19
@baermat baermat merged commit 2a0bcdb into main Oct 15, 2025
11 checks passed
@baermat baermat deleted the sns/v2-sms-attribute-operations branch October 15, 2025 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws:sns Amazon Simple Notification Service docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants