3

As of now, I have an API and an existing AWS Lambda that more or less have the same functionality. What I was trying to do, was instead of performing the same task in each project, I was attempting to have the API itself imply trigger the lambda. At the moment, sending it data isn't my primary concern, but that would be something I would try to do. That said, in Java, if you have all the credentials, the lambda name, and so on, is it possible to trigger an AWS Lambda locally and eventually through an API?

I've been going through a few solutions now, but it seems that many of them involve redeploying the lambda, or making a new one altogether. At the moment, I've been using these resources, A, B, C, and D.

My current function in my API looks something like this. The one in my lambda, let's call it foobar-lambda for now, is pretty much the same.

public Entity<Foos> Foos(@RequestHeader(value= "ApiKey", required = false) String apiKey,
                                                         @RequestParam String data) {
    Foos foos = FoosService.getFoos(data);
    Entity<Foos> response = null;

    if (foos != null) {
        response = Entity.ok().body(foos);
    } else {
        response = new Entity<>(HttpStatus.NOT_FOUND);
    }

    return response;
}

What I'd like to change this to, is something like this:

void Entity<Foos> Foos(@RequestHeader(value= "ApiKey", required = false) String apiKey,
                                                         @RequestParam String data) {
    triggerAndSend("foobar-lambda",data);
}

So, in this context, I'm trying to figure out exactly how to create the void triggerAndSend(String lambdaTarget, Integer... data) function. Ideally, I'd run this, and I'd be able to see that my lambda was triggered. Do I have to add an additional trigger in my Lambda to catch these? Is it possible, and if so, does anyone have any recommendations for how I can accomplish my goal?

0

1 Answer 1

2

This AWS Blog post describes one way to do what you're describing: Invoking AWS Lambda Functions from Java. It involves defining a Plain Old Java Object for the return value and an interface for the lambda function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.