title: How to call an aws java lambda function from another AWS Java Lambda function when both are in same account, same region
body: <p>I have a java aws lambda function or handler as AHandler that does some stuff e.g. It has been subscribed to SNS events, It parses that SNS event and log relevant data to the database. </p>
  
  <p>I have another java aws lambda BHandler, Objective of this BHandler to receive a request from AHandler and provide a response back to AHandler. Because BHandler's objective is to provide a response with some json data. and that would be used by the AHandler.</p>
  
  <p>May I see any clear example which tells how we can do such things ?</p>
  
  <p>I saw this example <a href="https://stackoverflow.com/questions/34720261/aws-lambda-how-to-call-lambda-function-from-simple-java-class">call lambda function from a java class</a> and <a href="https://java.awsblog.com/post/Tx2J2LPKTTVU93H/Invoking-AWS-Lambda-Functions-from-Java" rel="noreferrer">Invoke lambda function from java</a></p>
  
  <p><strong>My question talks about that situation, when one aws java lambda function (or handler) calls to another aws java lambda function when both are in same region, same account,same vpc execution stuff, same rights.</strong> In that case aws java lambda function can directly call( or invoke) to another  or still it has to provide aws key,region  etc stuff (as in above links) ? A clear example/explanation would be very helpful.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The AHandler who is calling another Lambda function (BHandler) , exist on same account have given complete <strong>AWSLambdaFullAccess</strong> with everything e.g. </p>
  
  <p>“iam:PassRole",
  "lambda:*",</p>
  
  <p>Here is the code to call :</p>
  
  <p><strong>Note :</strong> Below code works when I call the same function with everything same from a normal java main function.  But its not working like calling from on lambda function (like ALambdaHandler calling BLambdaHandler as a function call). <strong>Even its not returning any exception. Its just showing timeout, its got stuck  at the code of: lambdaClient.invoke</strong></p>
  
  <pre><code>String awsAccessKeyId = PropertyManager.getSetting("awsAccessKeyId");
          String awsSecretAccessKey = PropertyManager.getSetting("awsSecretAccessKey");
          String regionName = PropertyManager.getSetting("regionName");
          String geoIPFunctionName = PropertyManager.getSetting("FunctionName");
  
          Region region;
          AWSCredentials credentials;
          AWSLambdaClient lambdaClient;
  
          credentials = new BasicAWSCredentials(awsAccessKeyId,
                  awsSecretAccessKey);
  
          lambdaClient = (credentials == null) ? new AWSLambdaClient()
                  : new AWSLambdaClient(credentials);
          region = Region.getRegion(Regions.fromName(regionName));
          lambdaClient.setRegion(region);
  
  
          String returnGeoIPDetails = null;
  
          try {
  
  
              InvokeRequest invokeRequest = new InvokeRequest();
              invokeRequest.setFunctionName(FunctionName);
              invokeRequest.setPayload(ipInput);
  
  
              returnDetails = byteBufferToString(
                      lambdaClient.invoke(invokeRequest).getPayload(),
                      Charset.forName("UTF-8"),logger);
          } catch (Exception e) {
  
              logger.log(e.getMessage());
          }
  </code></pre>
  
  <p><strong>EDIT</strong>
  I did everything as suggested by others and followed everything. At the end I reached to AWS support, and the problem was related to some VPC configurations stuff, and that got solved.If you have encountered similar stuff, then may be check security configs, VPC stuff.</p>