I have a node.js application where I am invoking a lambda function through AWS SDK and I'm trying to handle lambda's errors in such a way that when it fails it calls an https endpoint from my application.
My application flow is as follow:
Invoke lambda with object with data
Lambda receives the object in the "event" and run its processes.
if lambda fails either by runtime error, timeout, etc I need it to call an endpoint on my application, including the same object that I sent when invoking the lambda function.
I have thought of using CloudWatch alarms along with SNS to call my application endpoint, but I am not aware if that's entirely possible, specially if CloudWatch alarm can receive the lambda 'event' object.
How could I achieve calling an endpoint after Lambda has failed?
Related
I have a problem with testing the Lambda destination - SNS.
Message is not published after Lambda has successfully run. I invoked the lambda in AWS cloud console using a test event.
Destination and topics are properly configured.
Side note, I can programmatically publish a message via sns.publish().
Question:
Is there a way to publish a message automatically to SNS once Lambda has successfully run via AWS console (using a test event)?
No. The console "synchronously invokes your function with the test event". It must be invoked asynchronously to use the destinations.
Call the lambda invoke API with --invocation-type Event for asynchronous invocation.
How do I create a rule that captures an HTTP GET that has some data and schedules the running of a lambda function at a specific time? I can write the lambda function but I am having trouble with creating an API endpoint to which I can send a "fetch" GET request. I tried creating an HTTP API in the API Gateway service. It returns this output:
{
"message": "Forbidden"
}
I am not much familiar with AWS. Please help me with creating a simple endpoint in AWS to which my app can send a GET request with some data, which will trigger an EventBridge rule to schedule the running of a lambda function at a specific time.
You don't need an API Gateway or a separate Lambda function.
To schedule the running of a specific Lambda function you can call the EventBridge put rule API.
You can find examples of the EventBridge user guide.
I am calling a lambda function from my API Gateway with Lambda proxy integration enabled. But when I am receive the event object in the function it is an empty object i.e. '{}'. I have tested the function with a test input available on AWS Console with dummy request object and it works fine. I am using AWS Cognito Pool as authorizer for the API Gateway Method.
In the function I have made an object that returns me dummy data and event object itself. When I hit the API from Postman or my frontend application it returns me with the dummy data and the event object is empty.
I have looked at the following Stackoverflow questions but to no avail.
Event Object is empty in AWS Lambda nodejs function
Passing event from API gateway to Lambda
Event object is empty in api gateway call to lambda
Api Gateway sends empty parameters to AWS lambda
Lambda event returns empty object
This is a small thing and is really hindering my progress. Would really appreciate any help.
Just made whole another Lambda and API Gateway setup and it worked. Must have been bad API Gateway configuration
I working on a project and I need to trigger a proxy API whenever a message is received by the AWS SQS Service. I went through couple of articles and found that API to SQS is possible but did not find anything related to SQS triggering API Gateway. Can somebody please guide.
It is not possible to invoke a Lambda function asynchronously with a proxy integration. You can do this with Lambda non-proxy integration.
Set up asynchronous invocation of the backend Lambda function - https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-integration-async.html
Another workaround is to use another function that is invoked synchronously by the API Gateway API and have that function invoke the function that is part of the Spring boo application asynchronously using the Lambda Invoke API or SDK equivalent.
https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html
For instance, you want Function A to be invoked asynchronously. To achieve this you would have the API Gateway API invoke Function B synchronously and have Function B invoke Function A asynchronously with the Invoke API.
Step Functions also cant be used as a workaround to invoke the REST APIs as this would not help. The Lambda functions are still invoked by the API Gateway API so you would still run into the limitation of a proxy integrations not being able to invoke Lambda asynchronously. You then decided that ECS would better suit your case as Lambda is not a good fit.
I'm using API Gateway-to-Lambda for a few micro-services but in at least one case the service will take 20-30 seconds to complete so in cases like this I'd like to pass back an immediate response to the client, something like:
status: 200
message: {
progressId: 1234
}
and then allow the Lambda Function to continue on (and periodically updating the "processId" somewhere that is accessible to a client. The problem is that if you call context.succeed(), context.fail(), or context.done() that apparently stops the lambda function from further execution and yet it's the only way I know to flush the stdout buffer back to the API Gateway.
This has led me to a second approach which I haven't yet try to tackle (and for simplicity sake would love to avoid) which involves API Gateway calling a "Responder" Lambda function that then asynchronously fires off the Microservice and then immediately responds to the API Gateway.
I've tried to illustrate these two options in sketch format below. I'd love to hear how anyone's been able to solve this problem.
Currently API Gateway requires that the AWS Lambda integration is synchronous. If you desire asynchronous invocation of your Lambda function, you have 2 options:
Invoking the Lambda asynchrously, either with an AWS integration calling InvokeAsync on Lambda, or using an intermediate service such as SNS or Kinesis to trigger the Lambda function.
You're #2 diagram, using a synchronous Lambda invoke to initiate the asynchronous invoke.
As of Apr/2016 is it is possible to create async Lambda execution through API Gateway by using AWS Service Proxy. See http://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-lambda.html
You can send the X-Amz-Invocation-Type header, it supports async calls through the Event value
You can optionally request asynchronous execution by specifying Event as the InvocationType
http://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax
Also, if you can't send it via your micro-service, you can configure this header to be passed by default through the Method Execution -> Integration Request -> HTTP Headers in your API Gateway Resource
This worked for me on a micro-service -> API Gateway -> Lambda scenario, like the mentioned on the question.