簡體   English   中英

AWS lambda 不發送返回到 SNS

[英]AWS lambda does not send return to SNS

我嘗試在 lambda function 完成后向 SNS 主題發送消息。

為此,我從 lambda 處理程序 function 返回消息 (python)。

Lambda 執行無誤並正確返回消息。 IAM 設置為允許 lambda 發布到特定的 SNS 主題。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "None",
            "Effect": "Allow",
            "Action": [
                "sns:Publish",
                "sns:Subscribe",
                "sns:ConfirmSubscription"
            ],
            "Resource": "arn:aws:sns:eu-central-1:123456789012:TOPIC"
        }
    ]
}

lambda 的簡化代碼是:

#import packages

def handler(event, context) -> dict:
    """
    lambda handler function for invoking session

    param event: json/dict like key:val mapping for regular lambda invocations with custom topics (e.g. different data pipeline stage, different customers etc.)
    param context: AWS logging

    return: dict like key:val mapping to deliver custom topics to AWS Service invocations
    """

    #-----# key:val mapping #-----#
    '''
    '''
    Message = event["Records"][0]["Sns"]["Message"]
    Message = Message.replace("'", "\"")
    Message = json.loads(Message)

    #does lot's of stuff here
    #eg. getting data from S3, posting data to S3
    #send topic to SNS is NOT used, since it should be configured by the general lambda settings as endpoint destination.



    # -----# update key:val mapping #-----#
    event = {
        "timestamp": timestamp
    }

    return event

還有什么事要做嗎? 因為在檢查 cloudwatch 日志后,沒有消息到達 SNS。

解決方案:使用Test進行測試,但調用lambda function不是異步的。 因此,錯誤在於調用的種類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM