Max Cabrera
Max Cabrera

Reputation: 121

AWS Lex: Intent permissions to execute Lambda as dialogCodeHook and fulfillmentActivity hook

I'm building a chatbot using the Node API AWS.LexModelBuildingService, and I want to attach all the new intents to trigger the same lambda function.

In the console I can do it manually, but this doesn't work for the project I'm working on, attaching the lambda must be done dynamically.

When I create the intent I can add the lines to attach the lambda, but then the permissions do not get updated and that's blocking me.

"dialogCodeHook": {
    "uri": "arn:aws:lambda:us-east-1:1111111:function:someFunction",
    "messageVersion": "1.0"
},
"fulfillmentActivity": {
    "type": "CodeHook",
    "codeHook": {
        "uri": "arn:aws:lambda:us-east-1:1111111:function:someFunction",
        "messageVersion": "1.0"
    }
}

How can I grant permissions to all current and future intents created with the Node AWS LEX API so they can call the Lambda?

Upvotes: 1

Views: 1354

Answers (1)

EpicVoyage
EpicVoyage

Reputation: 754

The aws command-line utility should allow you to automate this:

aws lambda add-permission --function-name [your-lambda-function-name] --statement-id [unique-policy-id] --action "lambda:InvokeFunction" --principal "lex.amazonaws.com"

Obviously you will need to insert your own function name.

The statement-id can be anything you want, but it can only be used one time as a statement-id on your account. It identifies this rule for IAM.

While I have not had to run this after updating my Lambda functions, I have seen reports from other people that they have to. YMMV.

Upvotes: 0

Related Questions