AWS SNS를 통해 Boto3 및 Python을 사용하여 Lambda를 통해 Apple 푸시 알림을 보냅니다.AWS Lambda/SNS 게시가 잘못된 끝점을 무시합니다.
from __future__ import print_function
import boto3
def lambda_handler(event, context):
client = boto3.client('sns')
for record in event['Records']:
if record['eventName'] == 'INSERT':
rec = record['dynamodb']['NewImage']
competitors = rec['competitors']['L']
for competitor in competitors:
if competitor['M']['confirmed']['BOOL'] == False:
endpoints = competitor['M']['endpoints']['L']
for endpoint in endpoints:
print(endpoint['S'])
response = client.publish(
#TopicArn='string',
TargetArn = endpoint['S'],
Message = 'test message'
#Subject='string',
#MessageStructure='string',
)
모두 정상적으로 작동합니다. 그러나 어떤 이유로 엔드 포인트가 유효하지 않은 경우 (현재로서는 장치에서 개발 빌드를 실행할 때마다 발생합니다. 다른 엔드 포인트를 얻으므로 발견되지 않거나 비활성화됩니다.) 람다 함수가 실패하고 호출됩니다 전부 다시. 이 특별한 경우, 예를 들어 두 번째 엔드 포인트가 실패하면 엔드 포인트 1에 무한대로 푸시를 반복해서 보냅니다.
유효하지 않은 끝점을 무시하고 계속 기능을 사용할 수 있습니까?
당신에게편집 감사합니다 내가 그것을 해결할 수 있었다 당신의 도움에
감사 : 이벤트 스트림에서 만료까지 실패
try:
response = client.publish(
#TopicArn='string',
TargetArn = endpoint['S'],
Message = 'test message'
#Subject='string',
#MessageStructure='string',
)
except Exception as e:
print(e)
continue
아직 BToS3 SNS 클라이언트를 처리기 외부로 이동하는 것이 좋습니다. 그런 식으로 처리기를 호출 할 때마다 새 클라이언트를 만들 필요가 없습니다. – garnaat
안녕하세요! 정보를 제공해 주셔서 감사합니다. – weka1