mirror of https://github.com/sgoudham/Tweeter.git
Add code to publish messages to sns topic
parent
446e3efeea
commit
d8465066c8
@ -0,0 +1,8 @@
|
|||||||
|
boto3==1.18.31
|
||||||
|
botocore==1.21.31
|
||||||
|
jmespath==0.10.0
|
||||||
|
python-dateutil==2.8.2
|
||||||
|
s3transfer==0.5.0
|
||||||
|
six==1.16.0
|
||||||
|
urllib3==1.26.6
|
||||||
|
python-decouple==3.4
|
@ -0,0 +1,25 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
from boto3 import Session
|
||||||
|
from decouple import config
|
||||||
|
|
||||||
|
|
||||||
|
def event_handler(event, context):
|
||||||
|
session: Session = configure_boto3_session()
|
||||||
|
client = session.client("sns")
|
||||||
|
|
||||||
|
client.publish(
|
||||||
|
TargetArn=config("sns_topic_arn"),
|
||||||
|
Message=json.dumps({'default': json.dumps(event)}),
|
||||||
|
MessageStructure='json'
|
||||||
|
)
|
||||||
|
|
||||||
|
return "Tweet Successfully Sent"
|
||||||
|
|
||||||
|
|
||||||
|
def configure_boto3_session() -> Session:
|
||||||
|
return Session(
|
||||||
|
aws_access_key_id=config("aws_access_key_id"),
|
||||||
|
aws_secret_access_key=config("aws_secret_access_key"),
|
||||||
|
region_name="eu-west-1"
|
||||||
|
)
|
Loading…
Reference in New Issue