Consider the contrived class below with a method A() that contains two lambda functions, a1() and a2(). I'd like to be able to invoke a2 from inside a1. However, when I do so, (the second line inside a1), I get the error
Error: variable “cannot be implicitly captured because no default capture mode has been specified”
I don't understand this error message. What am I supposed to be capturing here? I understand that using [this] in the lambda definition gives me access to methods in class foo but I'm unclear as to how to do what I want.
Thanks in advance for setting me straight on this.
class foo
{
void A()
{
auto a2 = [this]() -> int
{
return 1;
};
auto a1 = [this]() -> int
{
int result;
result = a2();
return result;
};
int i = a1();
int j = a2();
}
};
To have your Lambda function assume an IAM role in another AWS account, do the following: Configure your Lambda function's execution role to allow the function to assume an IAM role in another AWS account. Modify your cross-account IAM role's trust policy to allow your Lambda function to assume the role.
The AWS Java SDK also provides a very handy class to invoke Lambda functions, InvokeRequest. We now need to create an object of this class, configure the Lambda function name, and also specify the payload. InvokeRequest request = new InvokeRequest(); request. withFunctionName(LAMBDA_FUNCTION_NAME).
If you want to orchestrate multiple lambda functions in your application, the best and recommended way is to use AWS Step Function. But if you just want to execute a lambda function from another lambda function, you can simply call the target lambda function from the source lambda function using AWS SDK.
It's generally frowned up for some good reasons, but as with most things, there are nuances to this discussion. In most cases, a Lambda function is an implementation detail and shouldn't be exposed as the system's API.
You need to capture a2
in order to odr-use a2
within the body of a1
. Simply capturing this
does not capture a2
; capturing this
only allows you to use the non-static members of the enclosing class. If you expect a2
to be captured by default, you need to specify either =
or &
as the capture-default.
[this, &a2] // capture a2 by reference
[this, &] // capture all odr-used automatic local variables by reference, including a2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With