Image Upload and Retrieval from Server Using AWS API Gateway Proxy+ and Lambda
There are lot of articles and code samples in internet where we can find bits and pieces on how to handle binary data in AWS Gateway and how to send form-data or how to process form-data in AWS Gateway proxy+.
But no one has given end to end working sample code for handling binary data or to handle form-data
So I have created a simple AWS Gateway using which you can upload and retrieve image or binary data from server.
- Login to your AWS Console
- Click on services. Under Compute select Lambda
- In AWS Lambda page, click on “Create function” button
5. Enter “proxy-lambda” in Function name text box
6. Leave other things as it is and click on “Create Function” button
7. Click on “Index.js” file
8. Copy paste the below code
9. Click on Deploy
10. Go to AWS Console, select AWS Gateway
11. Click on “Create API” button
12.
13. Select “REST API”
14. Click on Actions and select “Create Resource”
15. In “New Child Resource” page select “proxy resource” checkbox
16. Click on “Create Resource” button
17. In Proxy Setup page, select “Integration type” as Lambda Function Proxy
18. Select the region where you have created “proxy-lambda” in previous step
19. In “Lambda Function” textbox enter “proxy-lambda”
20. Click on “Save” button
21. “Add Permission to Lambda Function” popup will appear. Click on “OK” button
In left menu, under “your-api-name”, click on Settings
22. Scroll down to “Binary Media Types”
23. Click on + “Add Binary Media Type”
24. In textbox enter “*/*” and click on “Save Changes” (*/* means any binary content type)
25. Now deploy API
26. Click on “Actions”, select “Deploy API”
27. In Deploy API popup, Select “[New Stage]”
28. Enter Stage name as “Dev” or “Prod” and click on “Deploy” button.
29. Test your new API in postman.