简体   繁体   中英

AWS lambda doesn't return the response

I'm using aws lambda for a slack app, and I'm handling an interactive response(so I need to send a response in 3 seconds) I invoke another lambda in my code with the Event type, and returning a return {"statusCode": 200} but I can't find in cw logs the returned value, the lambda execute with no issues but there is no returned value.

this is my code:

import logging
from urllib.parse import parse_qs

import utils.slack.client as slack
from functions.flows.update_zendesk_ticket import pass_to_pso
from lambda_warmer.lambda_warmer import lambda_warmup

from utils.common import invoke_lambda, PSO_NOC_ALERTS

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)


@lambda_warmup()
def lambda_handler(event, context):
    logger.info(f'this is the event: {event}')
    logger.info(f'this is the context: {context}')
    params = dict(parse_qs(event['body'], keep_blank_values=False))
    if "payload" in params:
        payload = eval(params["payload"][0].replace('false', 'False').replace('null', 'None').replace('true', 'True'))
        if payload["type"] == "message_action":
            logger.info(f'{payload["user"]["username"]} clicked on {payload["view"]["callback_id"]}')
        elif payload["type"] == "view_submission":
            logger.debug(payload)
            logger.info(f'{payload["user"]["username"]} submitted {payload["view"]["callback_id"]}')
            submitted_data = payload["view"]["state"]["values"]
            logger.info(submitted_data)
            if payload["view"]["callback_id"] == "pass_to_pso":
                result = pass_to_pso_handler(submitted_data)
                return result
    return {"statusCode": 200}


def pass_to_pso_handler(submitted_data):
    pso_slack_id = submitted_data["pso"]["pso_select-action"]["selected_user"]
    slack_client = slack.SlackClient()
    pso_email = slack_client.get_email_from_slack(pso_slack_id)
    zd_ticket_id = submitted_data["ticket_id"]["ticket_id-action"]["value"]
    thread_link = submitted_data["thread_link"]["thread_link-action"]["value"]
    reply_language = submitted_data["reply_language"]["reply_language-action"]["selected_option"][
        "value"]
    reply_type = submitted_data["reply_type"]["reply_type-action"]["selected_option"]["value"]
    pass_to_pso(pso_email=pso_email, ticket_id=zd_ticket_id, thread_link=thread_link,
                reply_language=reply_language, reply_type=reply_type)
    pso_name = pso_email.split('@')[0]
    invoke_lambda({
        "pso": pso_name,
        "ticket id": zd_ticket_id,
        "channel_id": PSO_NOC_ALERTS
    }, "Event")
    return {"statusCode": 200}

the invoke function:

def invoke_lambda(payload, invocation_type):
    client = boto3.client('lambda', 'us-east-1')
    response = client.invoke(
        FunctionName=SLACK_MESSAGE_LAMBDA,
        InvocationType=invocation_type,
        Payload=bytes(json.dumps(payload), encoding='utf8'))

and this is the last rows of my cw logs在此处输入图像描述

I think the only way to log your return to CloudWatch Logs by printing it. Or else, it is only visible to your function's integrations such as API Gateway .

import json

status = {"statusCode": 200}
print(json.dumps(status))

return status

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM