Tun Lin Aung
Tun Lin Aung

Reputation: 349

How to access AWS API endpoints by java

I am beginner of AWS and I have unclear points on connecting AWS API endpoints. I was unable to access AWS API endpoints from java client. Every times, it failed.

It failed by this error.

Calling...


Exception in thread "main" com.amazonaws.AmazonClientException: Unable to execute HTTP request: Connection timed out: connect  
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:642)    
    at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:400)    
    at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:362) 
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:311)  
    at com.amazonaws.services.lambda.AWSLambdaClient.invoke(AWSLambdaClient.java:1925) 
    at com.amazonaws.services.lambda.AWSLambdaClient.invoke(AWSLambdaClient.java:1029) 
    at com.amazonaws.services.lambda.invoke.LambdaInvokerFactory$LambdaInvocationHandler.invoke(LambdaInvokerFactory.java:121) 
    at com.sun.proxy.$Proxy7.getAllCategory(Unknown Source)    
    at testPrj.LamdaTest.main(LamdaTest.java:43) Caused by: java.net.ConnectException: Connection timed out: connect

Even though I tried to connect from the browser, it failed. It is GET request so I don't need to pass any request parameters.

https://xxx.execute-api.ap-northeast-1.amazonaws.com/prod/listall

Error is : **{"message":"Missing Authentication Token"}**

Upvotes: 1

Views: 1273

Answers (1)

ataylor
ataylor

Reputation: 66069

It looks like you are trying to invoke your lambda function at the URL you are setting as the endpoint. The endpoint is where the API client sends it's API calls. It is not related to where you'd browse to invoke your lambda. The valid lambda endpoints are listed here: http://docs.aws.amazon.com/general/latest/gr/rande.html#lambda_region. Incidentally, you should either set the endpoint, or call setRegion/configureRegion, but not both.

To invoke your lambda, use the invoke() API call on com.amazonaws.services.lambda.AWSLambdaClient or the AWS CLI (aws lambda invoke --function-name GetCategoryAction).

If you want to make your lambda accessible on the web as an API, you might want to look at the Amazon API Gateway service.

Upvotes: 2

Related Questions