简体   繁体   中英

AWS Lambda: function was created successfully but an error occurred when creating the trigger: Cannot read property 'includes' of undefined

I am trying to create a Lambda function off of the AWS-managed slack-echo-command-python blueprint and whenever I hit create, it comes back with "Your Lambda function "test_lambda_01" was successfully created, but an error occurred when creating the trigger: Cannot read property 'includes' of undefined." I am not sure what this means.

The trigger is supposed to be an AWS API Gateway that is created and attached automatically. I have tried to go create one through the Management Console and then add it to the triggers on the Lambda function manually. It gets added successfully but I get back "502_service_error" when I try to use my Slack slash command. It currently is supposed to accept all call types by default (will change later but I want to get something working).

I have changed the endpoint in the Slack settings to the correct one. I can see it being called in the CloudWatch metrics.

I edited the Lambda Function code to return this on every call, just for testing purposes. I am 99% sure that this is a valid response to give to Slack as most/all of it was copied from an example. It is valid JSON according to https://jsonlint.com/ .

{
    "body": {
        "blocks": [{
                "text": {
                    "text": "*It's 80 degrees right now.*",
                    "type": "mrkdwn"
                },
                "type": "section"
            },
            {
                "text": {
                    "text": "Partly cloudy today and tomorrow",
                    "type": "mrkdwn"
                },
                "type": "section"
            }
        ],
        "response_type": "ephemeral"
    },
    "headers": {
        "Content-Type": "application/json"
    },
    "statusCode": "200"
}

I have tested the Lambda Function with their default test and it returns the above. The API Gateway appears under the triggers. Do I need to attach more permissions to the API Gateway (it already has permission to invoke the lambda function)? Also, what was I doing incorrectly when trying to create the function from the blueprint?

Please let me know if you want any additional information.

You need to stringify the body parameter in the response.

https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html

{
    "isBase64Encoded": true|false,
    "statusCode": httpStatusCode,
    "headers": { "headerName": "headerValue", ... },
    "multiValueHeaders": { "headerName": ["headerValue", "headerValue2", ...], ... },
    "body": "..."
}

if you see the body parameter above, it is a string.

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