{"id":5688,"library":"publish-event-sns","title":"Publish Event SNS","description":"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.","status":"active","version":"0.0.3","language":"en","source_language":"en","source_url":"https://github.com/msantino/publish-event-sns","tags":["aws","sns","messaging","publish-subscribe","boto3"],"install":[{"cmd":"pip install publish-event-sns","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Likely underlying AWS SDK for SNS interaction.","package":"boto3","optional":false}],"imports":[{"note":"Assumed main function/class based on library name and common Python packaging patterns; specific API is not documented. If this import fails, direct boto3 usage (import boto3) is the alternative.","symbol":"publish_event","correct":"from publish_event_sns import publish_event"}],"quickstart":{"code":"import os\nimport json\nfrom publish_event_sns import publish_event # Assumed import based on library name\n\n# Fallback to boto3 if 'publish_event_sns' module is not found or has a different API\ntry:\n    from publish_event_sns import publish_event\nexcept ImportError:\n    import boto3\n    print(\"Using boto3 directly as 'publish_event_sns' module not found or API differs.\")\n    def publish_event(topic_arn, message, message_attributes=None, region_name=None):\n        sns_client = boto3.client(\n            'sns',\n            region_name=region_name or os.environ.get('AWS_REGION', 'us-east-1'),\n            aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),\n            aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', '')\n        )\n        response = sns_client.publish(\n            TopicArn=topic_arn,\n            Message=json.dumps(message),\n            MessageAttributes=message_attributes or {}\n        )\n        return response\n\n# Replace with your actual SNS Topic ARN\nSNS_TOPIC_ARN = os.environ.get('SNS_TOPIC_ARN', 'arn:aws:sns:REGION:ACCOUNT_ID:YOUR_TOPIC_NAME')\n\n# Example message and attributes\nevent_message = {\n    'detail-type': 'OrderCreated',\n    'source': 'my.application',\n    'detail': {\n        'orderId': '12345',\n        'customerEmail': 'test@example.com'\n    }\n}\n\nmessage_attrs = {\n    'eventType': {\n        'DataType': 'String',\n        'StringValue': 'OrderCreated'\n    },\n    'priority': {\n        'DataType': 'Number',\n        'StringValue': '1'\n    }\n}\n\ntry:\n    response = publish_event(SNS_TOPIC_ARN, event_message, message_attrs, region_name='us-east-1')\n    print(f\"Message published: {response.get('MessageId')}\")\nexcept Exception as e:\n    print(f\"Error publishing message: {e}\")\n    print(\"Ensure AWS credentials and SNS_TOPIC_ARN are correctly configured.\")\n","lang":"python","description":"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."},"warnings":[{"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.","message":"The `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.","severity":"gotcha","affected_versions":"0.0.3"},{"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\"}`.","message":"AWS 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.","severity":"breaking","affected_versions":"All versions (AWS SDK behavior)"},{"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.","message":"Messages 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.","severity":"gotcha","affected_versions":"All versions (AWS SNS service limit)"},{"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')`.","message":"SNS 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.","severity":"gotcha","affected_versions":"All versions (AWS SNS service behavior)"},{"fix":"Configure a NAT Gateway in a public subnet for your private VPC subnets, or create a VPC endpoint for SNS in your account.","message":"If 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.","severity":"gotcha","affected_versions":"All versions (AWS networking configuration)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}