问题
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