I am able to run AWS lambda using postman. I want to use the event to run unit test along it. I am not sure how I can generate the event.json file.
I tried logging event that I receive in my handleRequest method on cloudwatch logs but it does not seem to be the right one.
you can find the Lambda event structures in the documentation. Here is the list for all the different event types, https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html.
In your case I would say the event you are looking for coming from API Gateway, you can find it here: https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html#apigateway-example-event
Related
I have an SQS queue with a supported DLQ for failures. I want to write a custom Lambda function in java (spring boot) to get the messages from this dlq, write it to a file, upload the file to an S3 bucket and send the file as an alert to a specified webhook.
I'm new to lambda and I hope this design can be implemented.
One requirement is that I want to execute the Lambda only once per day. So let's say at 6:00 am everyday. I want all the messages in the queue to be written to a file.
I'm trying to see examples of RequestHandler being implemented where the messages in the queue are received and iterated to be saved in the file one at a time.
I'm not sure how to configure the lambda such that it runs only once per day instead of each time a message entering the DLQ.
Any documentation relating to these queries will be really helpful. Please critique my expected implementation and offer any better solutions for the same.
You can have your lambda code run on any schedule (once per day for your case) using CloudWatch Event Schedule.
To create the schedule, follow this link
In you lambda code, you can fetch the messages from DLQ and process them iteratively.
You no need to use Spring framework in AWS Lambda use Java only
Use Lambda with Cloud watch cron expression and schedule daily run.
Write your own logic
https://docs.aws.amazon.com/lambda/latest/dg/java-samples.html
https://www.freecodecamp.org/news/using-lambda-functions-as-cronjobs/
Im working on a lambda function that get's triggered from Kinesis streams.
I'm new to the aws kind of stuff so im just wondring if there is a way to debug localy the lambda function !
What i'm doing right now is every time i want to test i need to deploy on integration invirenement and it's kind of painefull and time consuming.
The function is built using java8.
Any propositions please !!
I have a AWS Lambda function which is deployed in console. Since, it will consume the message from some external queue automatically,I want it to be keep on running continuously instead of scheduling.
How can I make aws lambda to run continuously?
You can add a trigger to your Lambda, and set the SQS queue you want to respond to. In the AWS console (on the web), you can either do this from the Lambda functions itself, or from SQS (i'd advise this strategy). The console will guide you through the details for setting up the proper security stuff.
More info on the setup:
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-configure-lambda-function-trigger.html
Some general info on consuming SQS messages in Lambda:
https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
Your preferred programming language probably has a client library that implements the API for you.
IMPORTANT: If you want to process your queue sequentially, make sure you set the reserved concurrency of your lambda to 0.
Also, if you use CLI or other automatic deploy tools, make sure to update your config files, so you don't overwrite your Lambda's settings on deploy.
EDIT: when you say external queue; you mean a non SQS queue?
I guess it could still be done with another system. Best way to do it is to raise an event. Trigger the Lambda with a http request when a message is added. If for some reason you can't do this, you could add a schedule for your Lambda, and run it, let's say every 5 minutes. More info on scheduling: https://docs.aws.amazon.com/eventbridge/latest/userguide/run-lambda-schedule.html
If instead of an external queue you could use the SQS provided by AWS you could set that queue as a trigger to your Lambda function and have it execute once a new item is set on the queue.
Is there way to build proper integration test for few AWS Lambdas interacting each other via AWS SNS topic?
I deployed two lambdas using Java.
The first one is subscribed to AWS SNS_topic#1. It filters and transforms SNS message and pushes modified data onto SNS_topic#2.
The second one lambda is subscribed to SNS_topic#2. It modifies SNS message and do http request onto external endpoint.
I need to build end-to-end Integration test to check whole interaction.
Actually there is a better way, you should check out the
https://github.com/localstack/localstack
and https://github.com/localstack/localstack-java-utils
This two tools will help you to test your serverless apps built on AWS
You can use the amazon-cli if you want to test it from your local.
amazon-cli will help you to manually trigger your lamda via aws lambda invoke the command.
Please install amazon-cli at your local from this link.
After that you can invoke the amazon 1st lamda from your cli with aws lamda command. It comes with many options like you can pass payload (supposed to be pass from SNS in actual scenario).
Executing AWS Lamda from Amazon-CLI Command details description
Example command:
aws lambda invoke --function-name your_function_name --invocation-type RequestResponse outfile.txt --payload file:requestFile.txt
I hope it helps.
So, for instance, I am executing multiple requests like this
for (final ParentReference previousParent : previousParents) {
driveService.parents().delete(fileResourceId, previousParent.getId()).execute();
}
Is there a way to execute them in a batch (I mean not like adding to a Collection and then calling execute on each element)?
If there is, will the batch request form some kind of single request to reduce number of API calls and server requests?
I've seen there is a BatchRequest class, but I can't figure if that's what I need and how to use it assuming I have access to com.google.api.services.drive.Drive service.
The BatchRequest takes two arguments and I can't seem to find how to even build it properly, if that's what I need in first place.
Yes, using a BatchRequest will allow you to perform multiple API requests within a simple HTTP request. More information on how to use batching in the Google APIs Java client library is available here: https://code.google.com/p/google-api-java-client/wiki/Batch