Skip to content

Instantly share code, notes, and snippets.

@ZZANZU
Created August 5, 2022 18:25
Show Gist options
  • Save ZZANZU/190fed9059d462f603f4786333a2efde to your computer and use it in GitHub Desktop.
Save ZZANZU/190fed9059d462f603f4786333a2efde to your computer and use it in GitHub Desktop.
import json
import boto3
resource = boto3.resource('sns')
def lambda_handler(event, context):
body = json.loads(event['body']) # 서비스에서 전달한 데이터
endpoint_arn = body['endpoint_arn'] # 클라이언트 기기의 endpointArn
platform_endpoint = resource.PlatformEndpoint(endpoint_arn)
title_txt = body['title'] # 푸시 메세지 제목
body_txt = body['body'] # 푸시 메세지 내용
message_template = "{ \"notification\": { \"body\": \"" + body_txt + "\", \"title\":\"" + title_txt + "\" }}"
message = {
'GCM': message_template
}
message = json.dumps(message)
# 푸시 메세지 전송(publish)
response = platform_endpoint.publish(
TargetArn=endpoint_arn,
MessageStructure='json',
Message=message
)
return {
'statusCode': 200,
'body': str(response)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment