Reputation: 474
I'd like a lambda called GoalsFeed to invoke another lambda called Goals using AWS.Lambda. This seems to work, except for two things:
I'm not sure how to pass a header through to the target service.
The FunctionName is "myapp-goals-get" (aka Goals) but I want to go to a specific path on that service - the three paths shown below are all valid, but i'm wanting to specify the "../owner/123" path.
Below is my first crack at this, can someone help me modify this to pass "tenantid" as a header and to ensure that when "myapp-goals-get" is invoked, it sees itself as being invoked from the path with "../owner/123" ?
// fetch back all goals by userid
var lambda = new AWS.Lambda({
region: 'us-east-1'
});
var payload = {};
payload[ "userId" ] = "123";
payload[ "tenantid" ] = "1";
const params = {
FunctionName: 'myapp-goals-get',
InvocationType: "RequestResponse",
Payload: JSON.stringify(payload)
};
lambda.invoke( params, function(error, data) {
console.log( "data: %s", JSON.stringify( data ) );
if( error ) {
context.done( 'error', error );
}
else if( data.Payload )
{
context.succeed( data.Payload )
}
});
Upvotes: 2
Views: 2759
Reputation: 474
My solution was to simply reset the pathParameters and pass the Event through to the child lambda.
event.pathParameters = { };
event.pathParameters.id = 123;
const tdParms = {
FunctionName : 'mylambda',
Payload: JSON.stringify( event )
};
lambda.invoke( tdParms, function( error, data ) {
...
}
Upvotes: 1
Reputation: 975
The proper way to handle this use-case is to setup a REST API with API-Gateway + Lambda using proxy integration ( to forward all HTTP Headers/body/etc to your lambda function )
You can then chain inside the same request or make another call to your API.
Upvotes: 1