# Resource Policy help - allow AWS Lex to access deployed Lambda function

**URL:** <https://forum.serverless.com/t/resource-policy-help-allow-aws-lex-to-access-deployed-lambda-function/7817>\
**Category:** Serverless Framework\
**Tags:** aws, lambda\
**Created:** [March 27, 2019, 4:24pm UTC](https://forum.serverless.com/t/resource-policy-help-allow-aws-lex-to-access-deployed-lambda-function/7817 "2019-03-27T16:24:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![degraaf](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/degraaf/32/5059_2.png) [@degraaf](https://forum.serverless.com/u/degraaf)\
**Post date:** [October 28, 2021, 7:23am UTC](https://forum.serverless.com/t/resource-policy-help-allow-aws-lex-to-access-deployed-lambda-function/7817/2 "2021-10-28T07:23:16Z")

</div>

Came across this a couple years later but have worked it out with some help from the solution mentioned here:

> [@Is it possible to use configure Lambda Function Resource-based Policies using serverless framework?](http://forum.serverless.com/t/is-it-possible-to-use-configure-lambda-function-resource-based-policies-using-serverless-framework/4932/8):
>
> Tigerwan, did you manage to solve this? I have a similar issue in that I need to create a resource-based function policy for a lambda function so that it can be invoked by CloudWatch events that don’t exist at deploy time (dynamically added cron events).

```auto
functions:
  lex-handler:
    description: 'Lex Chatbot Lambda function'
    handler: index.handler
    timeout: 20 # optional, in seconds, default is 6
resources:
  Resources:
    #
    # Lambda resource permission to allow Lex to invoke it
    # NOTE - Serverless tries to create resources first so you'll need to comment this
    # out on first install and then run again to apply this permission
    #
    LambdaPermissionInvokeFromLex:
      Type: AWS::Lambda::Permission
      Properties:
        FunctionName: arn:aws:lambda:${aws:region}:${aws:accountId}:function:${self:service}-${self:provider.stage}-lex-handler
        Action: lambda:InvokeFunction
        Principal: lexv2.amazonaws.com

```

One caveat is that it tries to create resources first and fails because the Lambda does not exist yet.

So I deployed once with the resource commented out and then uncommented and ran again once the Lambda was created. There might be a better solution to that though.

---

_[View the full topic](https://forum.serverless.com/t/resource-policy-help-allow-aws-lex-to-access-deployed-lambda-function/7817)._
