Registry / aws / publish-event-sns

publish-event-sns

JSON →
library0.0.3pypypi✓ verified 24d ago

This Python library, currently at version 0.0.3, aims to simplify publishing messages to AWS SNS topics with attributes. Given its minimal version and summary, it is likely a lightweight wrapper around the official AWS SDK for Python, `boto3`. It appears to be a niche utility, as detailed documentation and a distinct release cadence are not publicly available beyond its PyPI entry.

pip install publish-event-sns
INSTALL
IMPORT
SIG · PUBLISH-EVENT-SNS
P
publish-event-sns
awspythonv0.0.3
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

publish_event
from publish_event_sns import publish_event
from publish_event_sns import publish_event

This quickstart demonstrates how to publish a structured message with attributes to an AWS SNS topic. It assumes the `publish-event-sns` library wraps `boto3`'s SNS client. It includes a fallback to direct `boto3` usage if the specific `publish_event_sns` module cannot be imported or its API differs, ensuring the example remains functional for general SNS publishing. AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) and the AWS_REGION should be configured via environment variables or other boto3-supported methods. The SNS_TOPIC_ARN must be replaced with your actual topic ARN.

import os import json from publish_event_sns import publish_event # Assumed import based on library name # Fallback to boto3 if 'publish_event_sns' module is not found or has a different API try: from publish_event_sns import publish_event except ImportError: import boto3 print("Using boto3 directly as 'publish_event_sns' module not found or API differs.") def publish_event(topic_arn, message, message_attributes=None, region_name=None): sns_client = boto3.client( 'sns', region_name=region_name or os.environ.get('AWS_REGION', 'us-east-1'), aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''), aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', '') ) response = sns_client.publish( TopicArn=topic_arn, Message=json.dumps(message), MessageAttributes=message_attributes or {} ) return response # Replace with your actual SNS Topic ARN SNS_TOPIC_ARN = os.environ.get('SNS_TOPIC_ARN', 'arn:aws:sns:REGION:ACCOUNT_ID:YOUR_TOPIC_NAME') # Example message and attributes event_message = { 'detail-type': 'OrderCreated', 'source': 'my.application', 'detail': { 'orderId': '12345', 'customerEmail': 'test@example.com' } } message_attrs = { 'eventType': { 'DataType': 'String', 'StringValue': 'OrderCreated' }, 'priority': { 'DataType': 'Number', 'StringValue': '1' } } try: response = publish_event(SNS_TOPIC_ARN, event_message, message_attrs, region_name='us-east-1') print(f"Message published: {response.get('MessageId')}") except Exception as e: print(f"Error publishing message: {e}") print("Ensure AWS credentials and SNS_TOPIC_ARN are correctly configured.")
Debug
Known issues
gotchaThe `publish-event-sns` library (v0.0.3) has minimal public documentation. The provided import paths and quickstart are based on assumptions of a thin wrapper around `boto3`. If the library's internal API differs, direct `boto3` usage for `sns.publish` will be necessary.
fix
Consult the library's source code on GitHub (if available and maintained) for its exact API, or default to using `boto3` directly for SNS publishing.
affects: 0.0.3
breakingAWS IAM permissions are crucial. The AWS user or role publishing messages must have `sns:Publish` permission for the target SNS topic. Without it, `boto3.client('sns').publish` (and by extension, likely `publish-event-sns`) calls will result in an `AuthorizationError` or similar access denied exceptions.
fix
Ensure your AWS IAM policy grants `sns:Publish` to the SNS topic's ARN. Example: `{"Action": ["sns:Publish"], "Effect": "Allow", "Resource": "arn:aws:sns:REGION:ACCOUNT_ID:YOUR_TOPIC_NAME"}`.
affects: All versions (AWS SDK behavior)
gotchaMessages published to SNS have a size limit of 256 KB (262,144 bytes). For SMS, the limit is 140-160 characters depending on encoding. Attempting to publish larger messages will result in an error.
fix
For messages exceeding 256KB, consider using the `amazon-sns-extended-client` library which leverages S3 to store large payloads and publishes an S3 object reference to SNS.
affects: All versions (AWS SNS service limit)
gotchaSNS FIFO topics require `MessageGroupId` and optionally `MessageDeduplicationId` parameters. Publishing to a FIFO topic without these will result in an error. Standard topics do not require these.
fix
When publishing to an SNS FIFO topic, include `MessageGroupId` and `MessageDeduplicationId` in your `publish` call parameters. For example: `sns_client.publish(TopicArn=topic_arn, Message=json.dumps(message), MessageGroupId='your_group_id')`.
affects: All versions (AWS SNS service behavior)
gotchaIf the publishing environment (e.g., AWS Lambda, EC2 instance) is within a private VPC, ensure it has outbound internet access via a NAT Gateway or a VPC endpoint for SNS to reach the SNS service. Otherwise, publish calls may time out.
fix
Configure a NAT Gateway in a public subnet for your private VPC subnets, or create a VPC endpoint for SNS in your account.
affects: All versions (AWS networking configuration)
Upgrade
Version history
0.0.3latest on PyPI · released May 22, 2020
Audit
Dependencies
boto3requiredLikely underlying AWS SDK for SNS interaction.
Agent activity
17 hits · last 30 days
node
14
Amazon
1
Resources
publish-event-sns — pip install publish-event-sns · libregistry