AWS lambda with Amazon API Gateway accessing multiple bucket objects - amazon-web-services

I have a created a React App for an existing simple BE implementation that stores all data in a JSON file, instead of a database. I was then asked to reimplement it, using AWS lambda, Amazon API gateway and storing the JSON file in a S3 bucket. Works fine, but I would like to have a side bar in my React APP, where I can access different JSON files. My question is, how is it possible to specify to my lambda function, which S3 object should it access each time?
Edit: Based on the comment, the API endpoints are used from an other service too, and cannot be altered, which is the root of my trouble.

AWS has now made lambda functions called publicly by having AWS Lambda Function URL. https://aws.amazon.com/blogs/aws/announcing-aws-lambda-function-urls-built-in-https-endpoints-for-single-function-microservices/
So, you can directly pass parameter of S3 object uri in lambda function from your app. You don't have to go via API gateway.

Related

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.

API Gateway - Read file from S3 which just created by a lambda function on the same rest endpoint

I have created a lambda function to convert a file on S3 and put the new converted file back to S3, the lambda function is triggered by rest api on api gateway. What I want to do is to reply the client by that same converted file when accessing the same endpoint. The option that I have in my mind is to return the file from lambda, which may not be a time optimized solution. My question is there another possible solution ? like calling the lambda function and forward the request to the created object in S3 ? I thought of forwarding one api resource to another one which will read from S3 directly, is it possible somehow ?
You probably want to return a pre-signed S3 url for the file you've just created, which the client can then follow (at most once, and for a limited time), to download that file directly from S3. The general documentation is here, but there will probably be a helper for it in an SDK for whatever language you're using.
Remember that API Gateway has a maximum timeout of 29 seconds. This is probably fine if you're just moving small amounts of data around in S3, but it's worth being aware of!

Web UI Wrapper for DynamoDB

Are there any resources out there for wrapping access to DynamoDB in a web UI?
Currently, I have a Lambda function that will populate a Dynamo table via S3 trigger. However, I would like to allow my team access to items in a table without needing to go into DynamoDB or upload a file to the S3 console. I'm not sure what's needed to fulfill this requirement, so any references would be greatly appreciated.
If it were me, I would create API Gateway endpoints for each method you want to expose, have the API Gateway call your Lambda function to retrieve the data you want, and return that as JSON thru the API to your browser - and then use the JS framework of your choice to present it to the user (I use Angular and Bootstrap, but any JS/CSS would work as well).

Using AWS Lambda to receive youtube push notifications

Is there a way using AWS lambda to receive notifications that a channel has uploaded a new video using https://developers.google.com/youtube/v3/guides/push_notifications (or any other method)?
I have currently tried using https://pubsubhubbub.appspot.com/subscribe using the URL for an API gateway which uses Lambda proxy to try and trigger my Lambda function but it doesn't seem to get there.
From here I want to be able to notify and store that information within AWS.
Don't mind what language that needs to be used with Lambda
Managed to work it out...
Created an open, unauthenticated API so that anything can talk to it with a basic AWS lambda 'Role' (not sure if that was important).
Then returned the hub.challenge in order to subscribe.

Upload file to s3 with custom response to client

I am trying to upload a file to s3 and then have lambda generate id, date.
I then want to return this data back to the client.
I want to avoid generating id and date on the client for security reasons.
Currently, I am trying to use API Gateway which invokes a lambda to upload into s3. However, I am having problems setting this up. I know that this is not a preferred method.
Is there another way to do this without writing my own web server. (I would like to use lambda).
If not, how can I configure my API Gateway method to support file upload to lambda?
You have a couple of options here:
Use API Gateway as an AWS Service Proxy to S3
Use API Gateway to invoke a Lambda function, which uses the AWS SDK to upload to S3
In either case, you will need to base64 encode the file content before calling API Gateway, and POST it in the request body.
We don't currently have any documentation on this exact use case but I would refer you to the S3 API and AWS SDK docs for more information. If you have any specific questions we'd be glad to help.
Thanks,
Ryan