AWS - Invoke Lambda within Lambda across regions

此生再无相见时 提交于 2019-12-24 21:00:58

问题


I would like to invoke Lambda B (US_EAST_1) within Lambda A (US_WEST_1) across regions. So Lambda A and B are situated in different regions. I have deployed both Lambdas to their regions and adjusted the IAM role:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "VisualEditor0",
        "Effect": "Allow",
        "Action": [
            "lambda:InvokeFunction",
            "lambda:InvokeAsync"
        ],
        "Resource": "*"
    }
]
}

This is the Java code of Lambda A:

ObjectMapper mapper = new ObjectMapper();

    String jsonString = "";
    System.out.println("Start CreateLambdaProxy");

    try {
        jsonString = mapper.writeValueAsString(input);
        String LambdaFunctionName = "arn:aws:lambda:us-east-1:bladiebla";


         AWSLambdaClient lambdaClient = new AWSLambdaClient();
         lambdaClient.withRegion(Regions.US_EAST_1);

         InvokeRequest invokeRequest = new InvokeRequest();
         invokeRequest.setFunctionName(LambdaFunctionName);
         invokeRequest.setPayload(jsonString);

         context.getLogger().log("Before Invoke");
         ByteBuffer payload = lambdaClient.invoke(invokeRequest).getPayload();
         context.getLogger().log("After Invoke");

         context.getLogger().log(payload.toString());
         context.getLogger().log("After Payload logger");

    } catch (JsonProcessingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    System.out.println("After");

I am able to invoke Lambda B with a test function. However, if I invoke it from Lambda A, nothing happens.

START RequestId: cc09cb06-ffb4-11e8-9c6b-7f1eee4bef0e Version: $LATEST
CreateLambdaProxy
Start CreateLambdaProxy
Before InvokeEND RequestId: cc09cb06-ffb4-11e8-9c6b-7f1eee4bef0e
REPORT RequestId: cc09cb06-ffb4-11e8-9c6b-7f1eee4bef0e  Duration: 25061.35 ms   Billed Duration: 25100 ms   Memory Size: 128 MB Max Memory Used: 92 MB  

I then tried invoking another Lambda that is in the same region as Lambda A (so no region difference) but that also did not give any result so I think it doesn't have anything to do with the region.

来源:https://stackoverflow.com/questions/53782781/aws-invoke-lambda-within-lambda-across-regions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!