Allow serverless lambda to be called by cloud watch2019 Community Moderator ElectionAWS Cloudwatch Event putTargets not adding Lambda event sourcesHow do I pass json inputs to a Cron scheduled Lambda deployed in Serverless using event?AWS SDK can't add Lambda as target to Cloudwatch eventNeed to configure serverless resource output to get api gateway api idServerless Framework: ways to achieve full “infrastructure as code”?Destroy resources created via Serverless without destroying Lambda endpointsserverless framework: trying to define a role for a lambda gives an undefined resource errorAWS Lambda Policy Length Exceeded - adding rules to a lambda functionWhat is causing Serverless deploy error: Unable to validate the following destination configurations, S3 InvalidArgument?Cognito permission to lambda function using serverless framework

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?

How would an energy-based "projectile" blow up a spaceship?

Is it a Cyclops number? "Nobody" knows!

Draw this image in the TIKZ package

Why aren't there more Gauls like Obelix?

Too soon for a plot twist?

Who has more? Ireland or Iceland?

Precision notation for voltmeters

What does *dead* mean in *What do you mean, dead?*?

Is this a crown race?

Tabular environment - text vertically positions itself by bottom of tikz picture in adjacent cell

What is Tony Stark injecting into himself in Iron Man 3?

I am the person who abides by rules but breaks the rules . Who am I

Was this cameo in Captain Marvel computer generated?

What would be the most expensive material to an intergalactic society?

Why do we call complex numbers “numbers” but we don’t consider 2-vectors numbers?

“I had a flat in the centre of town, but I didn’t like living there, so …”

How to educate team mate to take screenshots for bugs with out unwanted stuff

Rationale to prefer local variables over instance variables?

Why does a car's steering wheel get lighter with increasing speed

Do I need a return ticket to Canada if I'm a Japanese National?

Professor forcing me to attend a conference, I can't afford even with 50% funding



Allow serverless lambda to be called by cloud watch



2019 Community Moderator ElectionAWS Cloudwatch Event putTargets not adding Lambda event sourcesHow do I pass json inputs to a Cron scheduled Lambda deployed in Serverless using event?AWS SDK can't add Lambda as target to Cloudwatch eventNeed to configure serverless resource output to get api gateway api idServerless Framework: ways to achieve full “infrastructure as code”?Destroy resources created via Serverless without destroying Lambda endpointsserverless framework: trying to define a role for a lambda gives an undefined resource errorAWS Lambda Policy Length Exceeded - adding rules to a lambda functionWhat is causing Serverless deploy error: Unable to validate the following destination configurations, S3 InvalidArgument?Cognito permission to lambda function using serverless framework










0















I have one lambda function within my serverless.yml. It looks somehow like this:



functions:
clean:
handler: app.run
events:
- schedule: rate(2 hours)


It works pretty well and out of the box lambda gets called every 2 hours. When I add new rule in AWS Console and sets the newly created lambda as a target it also works. Both AWS Console and Serverless framework creates on the background policy that events.amazonaws.com service can invoke this specific function. The policy looks somehow like this:




"Sid":"AWSEvents_rule_name_test",
"Effect":"Allow",
"Principal":
"Service":"events.amazonaws.com"
,
"Action":"lambda:InvokeFunction",
"Resource":"arn:aws:lambda:eu-central-1:<account_id>:function:<lambda_name>",
"Condition":
"ArnLike":
"AWS:SourceArn":"arn:aws:events:eu-central-1:<account_id>:rule/<rule_name>"






I would like to define rules programatically and without the need to maintain those permissions. What I do is I create rule, then I create target similarly as described in docs https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html. Without the permission step it doesnt work. I would like to have generic permission on the serverless.yml level that enables the lambda to be called by any existing or not yet existing rules (so I care only about rules and targets). I mean something that would say:
"Grant cloud watch permission to invoke any lambda function with any rule defined on my account". That would increase usability of my function alot more.



Is it possible to define same policy that gets usually generated by AWS Console (code above) but little more generic and within serverless.yml file?



Update:
I end up trying example bellow. It was supposed to create "generic" rule:



functions:
clean:
handler: app.run
events:
- schedule: rate(2 hours)
resources:
Resources:
cleanLambdaPermission:
DependsOn:
# This is how serverless converts function name. Has to be update accordingly when lambda gets renamed.
- cleanLambdaFunction
Type: AWS::Lambda::Permission
Properties:
FunctionName:
"Fn::GetAtt": [ cleanLambdaFunction, Arn ]
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: "arn:aws:events:eu-central-1:<account_id>:rule"



Though it showed up it didnt work and my lambda never got called by programatically created rules until I added explicit SourceArn that maps exactly one rule to one single specific function. I am doing it also programatically in three steps:
1. Create rule.
2. Create target.
3. Create permission.



For delete I need proceed in reverse order. I didnt find if this (not allowing wildcards) is bug or intentional behaviour.










share|improve this question




























    0















    I have one lambda function within my serverless.yml. It looks somehow like this:



    functions:
    clean:
    handler: app.run
    events:
    - schedule: rate(2 hours)


    It works pretty well and out of the box lambda gets called every 2 hours. When I add new rule in AWS Console and sets the newly created lambda as a target it also works. Both AWS Console and Serverless framework creates on the background policy that events.amazonaws.com service can invoke this specific function. The policy looks somehow like this:




    "Sid":"AWSEvents_rule_name_test",
    "Effect":"Allow",
    "Principal":
    "Service":"events.amazonaws.com"
    ,
    "Action":"lambda:InvokeFunction",
    "Resource":"arn:aws:lambda:eu-central-1:<account_id>:function:<lambda_name>",
    "Condition":
    "ArnLike":
    "AWS:SourceArn":"arn:aws:events:eu-central-1:<account_id>:rule/<rule_name>"






    I would like to define rules programatically and without the need to maintain those permissions. What I do is I create rule, then I create target similarly as described in docs https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html. Without the permission step it doesnt work. I would like to have generic permission on the serverless.yml level that enables the lambda to be called by any existing or not yet existing rules (so I care only about rules and targets). I mean something that would say:
    "Grant cloud watch permission to invoke any lambda function with any rule defined on my account". That would increase usability of my function alot more.



    Is it possible to define same policy that gets usually generated by AWS Console (code above) but little more generic and within serverless.yml file?



    Update:
    I end up trying example bellow. It was supposed to create "generic" rule:



    functions:
    clean:
    handler: app.run
    events:
    - schedule: rate(2 hours)
    resources:
    Resources:
    cleanLambdaPermission:
    DependsOn:
    # This is how serverless converts function name. Has to be update accordingly when lambda gets renamed.
    - cleanLambdaFunction
    Type: AWS::Lambda::Permission
    Properties:
    FunctionName:
    "Fn::GetAtt": [ cleanLambdaFunction, Arn ]
    Action: "lambda:InvokeFunction"
    Principal: "events.amazonaws.com"
    SourceArn: "arn:aws:events:eu-central-1:<account_id>:rule"



    Though it showed up it didnt work and my lambda never got called by programatically created rules until I added explicit SourceArn that maps exactly one rule to one single specific function. I am doing it also programatically in three steps:
    1. Create rule.
    2. Create target.
    3. Create permission.



    For delete I need proceed in reverse order. I didnt find if this (not allowing wildcards) is bug or intentional behaviour.










    share|improve this question


























      0












      0








      0








      I have one lambda function within my serverless.yml. It looks somehow like this:



      functions:
      clean:
      handler: app.run
      events:
      - schedule: rate(2 hours)


      It works pretty well and out of the box lambda gets called every 2 hours. When I add new rule in AWS Console and sets the newly created lambda as a target it also works. Both AWS Console and Serverless framework creates on the background policy that events.amazonaws.com service can invoke this specific function. The policy looks somehow like this:




      "Sid":"AWSEvents_rule_name_test",
      "Effect":"Allow",
      "Principal":
      "Service":"events.amazonaws.com"
      ,
      "Action":"lambda:InvokeFunction",
      "Resource":"arn:aws:lambda:eu-central-1:<account_id>:function:<lambda_name>",
      "Condition":
      "ArnLike":
      "AWS:SourceArn":"arn:aws:events:eu-central-1:<account_id>:rule/<rule_name>"






      I would like to define rules programatically and without the need to maintain those permissions. What I do is I create rule, then I create target similarly as described in docs https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html. Without the permission step it doesnt work. I would like to have generic permission on the serverless.yml level that enables the lambda to be called by any existing or not yet existing rules (so I care only about rules and targets). I mean something that would say:
      "Grant cloud watch permission to invoke any lambda function with any rule defined on my account". That would increase usability of my function alot more.



      Is it possible to define same policy that gets usually generated by AWS Console (code above) but little more generic and within serverless.yml file?



      Update:
      I end up trying example bellow. It was supposed to create "generic" rule:



      functions:
      clean:
      handler: app.run
      events:
      - schedule: rate(2 hours)
      resources:
      Resources:
      cleanLambdaPermission:
      DependsOn:
      # This is how serverless converts function name. Has to be update accordingly when lambda gets renamed.
      - cleanLambdaFunction
      Type: AWS::Lambda::Permission
      Properties:
      FunctionName:
      "Fn::GetAtt": [ cleanLambdaFunction, Arn ]
      Action: "lambda:InvokeFunction"
      Principal: "events.amazonaws.com"
      SourceArn: "arn:aws:events:eu-central-1:<account_id>:rule"



      Though it showed up it didnt work and my lambda never got called by programatically created rules until I added explicit SourceArn that maps exactly one rule to one single specific function. I am doing it also programatically in three steps:
      1. Create rule.
      2. Create target.
      3. Create permission.



      For delete I need proceed in reverse order. I didnt find if this (not allowing wildcards) is bug or intentional behaviour.










      share|improve this question
















      I have one lambda function within my serverless.yml. It looks somehow like this:



      functions:
      clean:
      handler: app.run
      events:
      - schedule: rate(2 hours)


      It works pretty well and out of the box lambda gets called every 2 hours. When I add new rule in AWS Console and sets the newly created lambda as a target it also works. Both AWS Console and Serverless framework creates on the background policy that events.amazonaws.com service can invoke this specific function. The policy looks somehow like this:




      "Sid":"AWSEvents_rule_name_test",
      "Effect":"Allow",
      "Principal":
      "Service":"events.amazonaws.com"
      ,
      "Action":"lambda:InvokeFunction",
      "Resource":"arn:aws:lambda:eu-central-1:<account_id>:function:<lambda_name>",
      "Condition":
      "ArnLike":
      "AWS:SourceArn":"arn:aws:events:eu-central-1:<account_id>:rule/<rule_name>"






      I would like to define rules programatically and without the need to maintain those permissions. What I do is I create rule, then I create target similarly as described in docs https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html. Without the permission step it doesnt work. I would like to have generic permission on the serverless.yml level that enables the lambda to be called by any existing or not yet existing rules (so I care only about rules and targets). I mean something that would say:
      "Grant cloud watch permission to invoke any lambda function with any rule defined on my account". That would increase usability of my function alot more.



      Is it possible to define same policy that gets usually generated by AWS Console (code above) but little more generic and within serverless.yml file?



      Update:
      I end up trying example bellow. It was supposed to create "generic" rule:



      functions:
      clean:
      handler: app.run
      events:
      - schedule: rate(2 hours)
      resources:
      Resources:
      cleanLambdaPermission:
      DependsOn:
      # This is how serverless converts function name. Has to be update accordingly when lambda gets renamed.
      - cleanLambdaFunction
      Type: AWS::Lambda::Permission
      Properties:
      FunctionName:
      "Fn::GetAtt": [ cleanLambdaFunction, Arn ]
      Action: "lambda:InvokeFunction"
      Principal: "events.amazonaws.com"
      SourceArn: "arn:aws:events:eu-central-1:<account_id>:rule"



      Though it showed up it didnt work and my lambda never got called by programatically created rules until I added explicit SourceArn that maps exactly one rule to one single specific function. I am doing it also programatically in three steps:
      1. Create rule.
      2. Create target.
      3. Create permission.



      For delete I need proceed in reverse order. I didnt find if this (not allowing wildcards) is bug or intentional behaviour.







      aws-lambda serverless-framework aws-serverless






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday







      svobol13

















      asked 2 days ago









      svobol13svobol13

      8451424




      8451424






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Yes, You can use wild cards '*' to make it generic.






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55026399%2fallow-serverless-lambda-to-be-called-by-cloud-watch%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Yes, You can use wild cards '*' to make it generic.






            share|improve this answer



























              0














              Yes, You can use wild cards '*' to make it generic.






              share|improve this answer

























                0












                0








                0







                Yes, You can use wild cards '*' to make it generic.






                share|improve this answer













                Yes, You can use wild cards '*' to make it generic.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 days ago









                Sudhakar NaiduSudhakar Naidu

                616




                616





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55026399%2fallow-serverless-lambda-to-be-called-by-cloud-watch%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                    Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                    How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page