Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
add UnsubscribeURL to SNS notification message (localstack#2467)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreipopa-who authored May 28, 2020
1 parent 6dcffb3 commit 1a184c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion localstack/services/awslambda/lambda_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,26 @@ def process_apigateway_invocation(func_arn, path, payload, headers={},
LOG.warning('Unable to run Lambda function on API Gateway message: %s %s' % (e, traceback.format_exc()))


def process_sns_notification(func_arn, topic_arn, subscription_arn, message, message_attributes, subject='',):
def process_sns_notification(func_arn, topic_arn, subscription_arn, message,
message_attributes, unsubscribe_url, subject='',):
event = {
'Records': [{
'EventSource': 'localstack:sns',
'EventVersion': '1.0',
'EventSubscriptionArn': subscription_arn,
'Sns': {
'Type': 'Notification',
'MessageId': str(uuid.uuid4()),
'TopicArn': topic_arn,
'Subject': subject,
'Message': message,
'Timestamp': timestamp_millis(),
'SignatureVersion': '1',
# TODO Add a more sophisticated solution with an actual signature
# Hardcoded
'Signature': 'EXAMPLEpH+..',
'SigningCertUrl': 'https://sns.us-east-1.amazonaws.com/SimpleNotificationService-000000000.pem',
'UnsubscribeUrl': unsubscribe_url,
'MessageAttributes': message_attributes
}
}]
Expand Down
4 changes: 4 additions & 0 deletions localstack/services/sns/sns_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,16 @@ def publish_message(topic_arn, req_data, subscription_arn=None):

elif subscriber['Protocol'] == 'lambda':
try:
external_url = external_service_url('sns')
unsubscribe_url = '%s/?Action=Unsubscribe&SubscriptionArn=%s' % (external_url,
subscriber['SubscriptionArn'])
response = lambda_api.process_sns_notification(
subscriber['Endpoint'],
topic_arn,
subscriber['SubscriptionArn'],
message,
message_attributes,
unsubscribe_url,
subject=req_data.get('Subject', [None])[0]
)
if isinstance(response, FlaskResponse):
Expand Down

0 comments on commit 1a184c0

Please sign in to comment.