Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Lambda permission in serverless

I'm running into an issue with Serverless v1.5 (latest version currently available at the time of writing)

I've to add permission to the lambda function and I'm trying to achieve this by creating a CF template and running along with the deploy of the function:

resources:
  Resources:
    logsGroup:
      Type: "AWS::Lambda::Permission"
      Properties: 
        Action: lambda:InvokeFunction
        FunctionName: 
          Fn::GetAtt:
            - "${self:custom.${opt:stage}.name}"
            - "Arn"
        Principal: "logs.amazonaws.com"
        SourceAccount:
          Ref: "AWS::AccountId"
        SourceArn: "arn:aws:logs:${self:provider.region}:*:log-group:*:*"

This is how it should look like. My problem is that when I try to deploy it I get an error which says that the function is not created yet which is understandable. How can I overcome to this issue? Any ideas?

like image 505
Mazzy Avatar asked Jan 10 '17 14:01

Mazzy


1 Answers

Not enough rep to add a comment - have you tried adding a DependsOn attribute to the Lambda Permission resource? Explicitly setting that property will result in CloudFormation waiting until the Lambda Function resource is created before creating this permission.

Also if you weren't already aware the .serverless folder that gets created in the root of your project contains the CloudFormation templates used by serverless, which can be helpful when troubleshooting unexpected CloudFormation behavior.

like image 66
ironmanwaring Avatar answered Sep 27 '22 19:09

ironmanwaring