0

So in a lot of AWS Lambda tutorials, it teaches us to write a few lines of code, package it, and upload it. enter image description here

Is there a code example where you can just trigger/call the lambda in your current project using the ARN or something? My current project is huge and I can't/it's not preferable to upload the function package to AWS Lambda, I just want to trigger it in my current code.

One link I found is: https://aws.amazon.com/blogs/developer/invoking-aws-lambda-functions-from-java/ but it does not work for me so far.

Apologies if it's been asked already; I didn't find anything useful to me.

EDIT:

My problem is the lambda function only gets invoked because I've uploaded it as a JAR (ie. its not a part of my main project, I just did it as a test), but I want to write the code to be invoked in my main project. I don't know how to invoke the lambda in my Java code. Like @MaxPower said, perhaps I have this all wrong and this is not possible.

7
  • 2
    Can you explain in more detail what problem you are facing? Your comment "it's not preferable to upload the function package to AWS Lambda, I just want to trigger it in my current code" makes no sense at all. Either you want to upload your Lambda function's code to the AWS Lambda service, or you don't want to use the AWS Lambda service at all. Commented Jun 21, 2017 at 18:45
  • My problem is I don't want to upload my lambda function through the AWS Lambda service console, but I do want to use the service (through Java code). Thanks for the feedback does that help? Commented Jun 21, 2017 at 19:15
  • 2
    That doesn't make any sense. What code do you plan on invoking if you don't upload the code to the Amazon Lambda service? Commented Jun 21, 2017 at 19:34
  • Hm okay this is why I need help; perhaps I'm missing some core concepts. I will write an edit in my original post. Commented Jun 21, 2017 at 19:37
  • @MaxPower done. I suppose by what you mean, some code must be uploaded to the AWS service Commented Jun 21, 2017 at 19:57

1 Answer 1

2

What I do is create an interface with the @LambdaFunction annotation.

public interface Foo {

@LambdaFunction(functionName = "LambdaName")
OutputObject doFoo(InputObject inputObject);

}

Then in the class that is to call the lambda I make a Lambda client

private final Foo fooCaller;

RunTest() {
    ProfileCredentialsProvider lambdaCredentialsProvider = new ProfileCredentialsProvider("lambda");
    AWSLambdaClientBuilder builder = AWSLambdaClientBuilder.standard().withCredentials(lambdaCredentialsProvider);
    builder.setRegion("us-east-1");
    AWSLambda awsLambda = builder.build();

    LambdaInvokerFactory.Builder lambdaBuilder = LambdaInvokerFactory.builder();
    lambdaBuilder.lambdaClient(awsLambda);

    fooCaller = lambdaBuilder.build(Foo.class);
}

then when you want to call the lambda

fooCaller.doFoo();
Sign up to request clarification or add additional context in comments.

2 Comments

can i private message you? I think I am getting more confused by the second.
Sure! Ask away!

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.