Calling AWS Lambda directly

0

Can I call an AWS Lambda function directly without using API GW, for example? I do not get any HTTP endpoint when I create a Lambda function but I get an ARN. Can I use ARN to directly call lambda function programmatically or I always have to go through a GW?

1개 답변
0
수락된 답변

Hi - Yes you can directly call lambda function programmatically. You can invoke Lambda functions directly with the Lambda console, the Lambda API, the AWS SDK, the AWS CLI, and AWS toolkits. You can also configure other AWS services to invoke your function, or you can configure Lambda to read from a stream or queue and invoke your function.

Reference : https://docs.aws.amazon.com/lambda/latest/dg/lambda-invocation.html

On more sample example is https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-lambda.html . This section provides examples of programming with the Lambda service client by using the AWS SDK for Java

        String functionName = args[0];

    InvokeRequest invokeRequest = new InvokeRequest()
            .withFunctionName(functionName)
            .withPayload("{\n" +
                    " \"Hello \": \"Paris\",\n" +
                    " \"countryCode\": \"FR\"\n" +
                    "}");
    InvokeResult invokeResult = null;

    try {
        AWSLambda awsLambda = AWSLambdaClientBuilder.standard()
                .withCredentials(new ProfileCredentialsProvider())
                .withRegion(Regions.US_WEST_2).build();

        invokeResult = awsLambda.invoke(invokeRequest);

        String ans = new String(invokeResult.getPayload().array(), StandardCharsets.UTF_8);

        //write out the return value
        System.out.println(ans);

    } catch (ServiceException e) {
        System.out.println(e);
    }

    System.out.println(invokeResult.getStatusCode());

Hope this helps

profile pictureAWS
전문가
답변함 3년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠