如何使用Java SDK列出与AWS Lambda函数关联的触发器 [英] How to list triggers associated with AWS Lambda function using Java SDK

查看:122
本文介绍了如何使用Java SDK列出与AWS Lambda函数关联的触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AWS Lambda控制台内部,如果您单击触发器"选项卡,则将为该lambda函数配置任何触发器,从而向您显示触发器列表.如何获取使用适用于AWS的Java SDK触发的已配置列表?

Inside AWS Lambda console if you click on Triggers tab it will show you list of triggers if any triggers are configured for that lambda function. How to get the list of configured triggered using Java SDK for AWS?

谢谢.

推荐答案

当您获得lambda函数的详细信息时,没有直接列出这些内容,而从UI的角度看,它们似乎是很奇怪的,这似乎有些奇怪.Lambda的一部分.有人已经指出了分配给lambda的策略文档,您可以使用该文档来确定允许调用该lambda的其他AWS资源.

It looks kind of strange that these aren't listed directly when you get the details of a lambda function, while from a UI point of view they seem to be part of the lambda. Someone already pointed to the policy document assigned to the lambda, which you can use to determine the other AWS resources which are allowed to invoke this lambda.

遇到此问题时,我正在Go中工作,但是Java的方法几乎是相同的.在执行过程中,它看起来像这样:

I was working in Go when running into this, but the approach for Java will be mostly the same. In go it looks something like this:

func(p *AWSParser) getEventTriggers(functionName string) *[]Trigger {

    var triggers []Trigger
    res2, err := p.lambdaSvc.GetPolicy(&lambda.GetPolicyInput{FunctionName: &functionName})

    if err == nil {
        polAsJson := gjson.Parse(*res2.Policy)
        polAsJson.Get("Statement").ForEach(func (_, value gjson.Result) bool {
            sid := value.Get("Sid").String()
            effect := value.Get("Effect").String()
            action := value.Get("Action").String()
            sourceArn := value.Get("Condition.ArnLike.AWS:SourceArn").String()

            triggers = append(triggers, Trigger{Sid: sid, Effect: effect, Action: action, SourceArn: sourceArn})
            return true
        })
    }

    return &triggers
}

基本上,您需要做的是:

Basically what you need to do is:

  1. 在lambda服务上,调用 getPolicy 函数,提供您的Lambda名称.
  2. 结果可以包含一个策略文档,该文档本身就是一个JSON字符串
  3. 通过此策略,您可以确定调用资源.
  1. on the lambda service call the getPolicy function, providing the name of your Lambda.
  2. The result can contain a policy document, which in itself is a JSON string
  3. From this policy you can determine the invoking resources.

作为一个示例,以下是对该lambda解析此策略的结果,该lambda可以从认知触发器触发:

As an example the following is the result of parsing this policy for a lambda which can be invoked from a cognito trigger:

    "Sid": "CSI_customMessage_eu-west-1qTL8mCdN9_CSI_customMessage",
    "Effect": "Allow",
    "Action": "lambda:InvokeFunction",
    "SourceArn": "arn:aws:cognito-idp:eu-west-1:###:userpool/###"

这篇关于如何使用Java SDK列出与AWS Lambda函数关联的触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆