Invoke Lambda function on button click in React - amazon-web-services

To start I just want to say that I'm really new to AWS overall (1-2 weeks). So I might not think correct from start.
I'm working on an app where I want to click a button in JSX and trigger a Lambda function that gets data from a dynamodb table and shows it in the UI.
I'm writing the infrastructure as code using aws cdk. How should I face this? Do you have any guides that I can follow?

Welcome! Please have a look on this guide.
With AWS, it's a best practice to create an AWS API Gateway, which acts as your HTTP/HTTPS/API web server.
Within this API gateway, you can integrate a Lambda function with a route (e.g. GET /users), where that Lambda function grabs the data from AWS DynamoDB process it as you wish and returns the output.
To integrate it with your code, you create an HTTP GET/POST request to the API gateway URL.

Related

Without using API gateway how can I get the URL for testing the lambda function developed in JAVA?

I am new to AWS lambda and want to know if it's feasible to test Lambda functions developed in JAVA using URLs if we don't wanna use AWS API Gateway.
Lambda function is giving me some records. I want to route those records to a URL.
I don't think there is. A Lambda function has no public endpoint. You need to connect it to something like a API Gateway, SNS Topic or others. There are a lot of options here. You can test a lambda manual by pressing the test button if you are in de AWS web interface. (Go to Lambda -> Click on your function -> check the upper right for the test button). You can use a predefined request or create your own.
A better solution is to test the function before it is even deployed. Just write unit tests and integrate that in your CI/CD system. If you need a actual running lambda function locally or in your CI/CD environment for integration testing I would suggest using AWS SAM to help you do that.

Create an api in api gateway to invoke a lambda function

I am working on a project and trying to use API Gateway to invoke a lambda function. The lambda function is used to update a DynamoDB item. The DynamoDB table is used to keep a running count of visitors to a web page. I need to create an API to invoke the lambda function but I'm not sure how to create the API. Any assistance is appreciated.
General steps would be:
Create AWS_PROXY integration between API Gateway and your Lambda function. The example of this is in the AWS tutorials: Set up Lambda proxy integrations in API Gatewa and in Tutorial: Build a REST API with HTTP proxy integration
Add/amend execution role to your function allowing it to access DynamoDB. This is exemplified in the AWS tutorial: Using AWS Lambda with Amazon DynamoDB.
Test the API. It can be done directly in API gateway console, or using external tools such as curl or Postman.
I figured out my issue. In my lamdba function, I needed to change the output to a JSON object. Once I made the change, I was able to get my API working. Here is a link to the fix.

AWS API Gateway POST Request for daily data load

I am someone who is totally new to REST APIs, pardon the newbie-ish mistakes.
My requirement is:
The source Database people wants to send JSON data on an hourly basis to an API endpoint which I publish. I am not sure of what all do I need to build to make sure it happens seamlessly. My target is to receive the data and create CSV files and save in it AWS S3 for further downstream processing.
My plan is, creating an AWS API Gateway endpoint which will accept POST requests and whenever anyone sends data through POST, the API Gateway will trigger AWS Lambda Function which will run Python to parse the JSON data to CSV and store in AWS S3. Is this thought valid? What all am I missing out? Are there best practices which needs to be implemented?
This architecture seems to be what you wanna do.
You wanna make sure that your API is secured with a key or via Cognito (more complex) and that your Lambda have the IAM permissions needed in order to access your bucket.
This post will help you understand the Lambda blueprint that is triggered when an object is upload to s3. Just change the Lambda trigger and a little bit the Python code and you're done.
Yes,this is a simple, typical serverless stack and it works perfectly fine.
Additionally, you may also focus on the authentication on the API Gateway end point to make it secure.

How to deploy a SpringBoot microservice application(RESTful) as serverless to AWS Lambda?

I have developed a simple microservice, REST based using Java 8 and Spring Boot2.0. It has its own REST end points which I can call using Postman and I get the response very well. Now I have doubt in understanding the design & architecture if I want to deploy the same application on AWS cloud. I want my application to behave as serverless so I want to deploy on AWS using its Lambda service.
Please assist to clear my following doubts :-
1) First, can I upload my whole application code to AWS Lambda in order to make it serverless?
2) If yes, then do I need to use AWS API Gateway (compulsorily) to invoke my Lambda function when the request passes through it?
3) If yes (point 2), then end points which are there in my original microservice code will become ineffective and will be overridden by new API Gateway end points?
My whole doubt is about end points, which end point will be used to invoke the Lambda functions?
Please assist to clarify my doubt. If there is any sample reference material then it will be really great.
Cheers
Spring Boot and AWS Lambda don't naturally go together IMO.
Lambda is pure code, it does not present itself as a HTTP Server, it is just triggered by one of the other AWS services (API Gateway, CloudWatch, S3, DynamoDB, Kinesis, SDK, etc.). The handler receives a JSON request from the calling service, and processes the request. Here is an example.
API Gateway does much of what Spring Boot provides for you. API Gateway is always online waiting for HTTP requests to come in, for which you only pay for incoming requests, you do not pay for idle (the definition of serverless IMO).
Once a request comes in, API Gateway wraps the request payload with some additional environmental data and sends it to your Lambda handler, which processes the request and returns some response to the client.
Saying that, if you don't want to restructure your service, there are a couple of options open to you:
Wrap into a Docker image and use an AWS Container Service, either using ECS or ElasticBeanstalk, neither of these are considered to be serverless.
I have not tried this, but according to AWS:
You can use the aws-serverless-java-container library to run a Spring Boot application in AWS Lambda. You can use the library within your Lambda handler to load your Spring Boot application and proxy events to it.
See links to Convert your SpringBoot project and Deploy it to AWS Lambda.
Hope this helps.

AWS Lambda http, where do I find the URL?

I am fairly new to AWS Lambda but sure can see the benefits of it and stumbled upon the superb framework Serverless to help me built solutions on Lambda.
I started out building solutions using AWS API Gateway but really need "internal" VPC API's and not public Internet facing API's like API GW creates.
I found that Servless indeed can expose a HTTP endpoint but I can't figure out how this is done and how the URL is created.
When I deploy the Lambda from Serverless it gives me the URL, e.g.:
https://uxezd6ry8z.execute-api.eu-west-1.amazonaws.com/dev/ping
I would like to be able to find (or create) this same http listener for already existing Lambdas so my question is how is the URL created and where is teh actual HTTP listener deployed?
You might be looking for the invoke url,
1. go to https://console.aws.amazon.com/apigateway
2. select api link (which you have deployed on aws lambda).
3. select stages in left side panel and
see the invoke url.
Adding a http listener can be done by going to your lambda function, selecting the 'triggers' tab and 'add trigger', finally selecting API Gateway - but as others mentioned this does create a public facing url.
Duh, I was in the wrong AWS logon previously so the API GW was not showing any matching Serverless API and that was why I couldn't understand how they did it...
Once I logged into the AWS account that hosts the Serverless structure I can see the API GW GET API's for the Serverless HTTP listener.