AWS Webhook (how to access the payload of a POST) - amazon-web-services

I created a webhook in AWS with the API Gateway and Lambda function. It all works but one silly thing... When I POST to the webhook, where do I access the payload? Also, how to I redirect he payload to a local folder or S3 bucket?

The event parameter (the first parameter) sent to the Lambda function will have an API Gateway Proxy event. One of the fields in that event is the body, which will be the payload (encoded to a string).
You can make an S3 API call to put the body of the payload in S3. Alternatively, you could have the data go directly to S3 by using a pre-signed url.

Related

Do not send raw body to AWS Lambda via API Gateway

I have an aws lambda function written in node. I have a HTTP API in API Gateway which calls this lambda function.
The "issue" that I'm having is that my request payload which is a JSON, is sent wrapped in a raw body along with a bunch of other fields which I don't really need in my lambda.
How can I have the HTTP API to only send my payload?
If I use a REST API, at least by default, it works the way I expect.

Integrating AWS Lambda and HTTP endpoint together in API Gateway?

Let's say I have a service to allow people to upload photos. I store these photos in S3, and to make it efficient, I use Cloudfront. In order to upload these photos to S3, I was recommended to use Lambdas with API Gateway. However, I'd also like to send this request to a custom HTTP endpoint as well, and return that in the response from the Gateway. So my ideal process is:
User submits upload photo
Photo gets sent to API Gateway
API Gateway calls Lambda to store photo in S3 and also forwards the request to custom backend API
Backend sends back some info
API Gateway sends back this info to client
Is this possible? From the integrations doc, it seems like I can only do Lambdas or HTTP custom endpoint. Not sure how to do both.
Your flow should be like this
Create a lambda endpoint to create signedUrl and return to frontend for s3 upload
Once you have the signed URL upload the pic to the signed URL from the frontend
Once the operation is successful either you can send a request to the lambda from the frontend or a event on the s3 bucket to do further processing

How to send a S3 bucket notification on SNS with a presigned url to new object uploaded?

I would like to configure a bucket notification on an S3 bucket so that every time a notification from a file being uploaded, it sends a message to an SNS topic with a pre signed url in the message so that file can be downloaded when consumed from an email.
File gets uploaded -> notification sent to SNS containing presigned url to recently updated object -> to SNS topic -> to email -> to user
I have tried setting up a topic, but couldn't get a presigned url inside the message, is there a way of setting this up without using a lambda or queue or other AWS services as intermediates?
You can't do this without additional services.
S3 is a storage service, as such it doesn't to much computation if any.
The simplest way would be to create a Lambda that gets triggered on S3 put object, generates the presigned url and sends a message to an SQS or SNS topic.
You'll need to use a Lambda for this unfortunately, it shouldn't be too much additional work.

AWS serverless - Modify cloudfront POST request to a GET Request for s3 website origin

I have a CloudFront distribution where the origin is set to an s3 website endpoint (serving static web app on s3)
Now my webapp on s3 needs some user information that is only provided via a POST request from an iframe.
I thought it would be possible to use Lambda#edge function on ViewerRequest stage, to capture the user info, and then modify the request to GET and append a token to the origin, before it requests the origin, thus allowing s3 to serve.
However i can't seem to get it to work. is this even possible?
You can't change the HTTP method in a Lambda#Edge trigger function, because it is read-only.
method (read-only)
The HTTP method of the viewer request.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#lambda-event-structure-request
What you can do is use the AWS SDK to send a request to S3 from within the trigger function, and use the object content retrieved, to generate a response directly from the trigger function.
Note that there are limits to the response size you can generate -- for Viewer Request, it's 40KB. For Origin Request, it's 1MB.
Of course, you don't need to fetch the content from S3, necessarily. You can fetch it from anywhere, or you can embed it in the function itself.
With this setup, since the function is generating a response, CloudFront never forwards the actual POST request to S3.

AWS API Gateway header for request in Authorizer

I am using AWS API Gateway for Communicating with Action on Google Console to AWS Lambda. In this scenario I am making a post call and I want to find the user in this call. I came to know that this is sent in the header. So I did the Following Steps:
Created a resource and method and that's working fine data is being passed successfuly between each other.
Now I want to pass the header to find the user so what I did was I use the authorizer from AWS API gateway console and then clicked on Create a authorizer.
Now I am confused in this scenario I want a header and body so what should I send it has in Lambda Event Payload.
Either Token or payload in case of token it's only sending the authorization part as a header.
So According to my understanding In my scenario I'll be needing Request. But in request what should I add as Identity Sources for header in the console.
Actually for the Above Problem We need to do the Implementation in Integration request in the AWS API Console. Go to the Mapping template in Integration request.
For Futher references use this article