Tuesday, 25 May 2021

AWS API gateway, S3

 

Tutorial: Create a REST API as an Amazon S3 proxy in API Gateway - Amazon API Gateway

Using REST API to upload files to the S3 bucket - BlueGrid : BlueGrid


AIM role



Edit Trust Relationship

{

  "Version": "2012-10-17",

  "Statement": [

    {

      "Effect": "Allow",

      "Principal": {

        "Service": "s3.amazonaws.com"

      },

      "Action": "sts:AssumeRole"

    },

    {

      "Effect": "Allow",

      "Principal": {

        "Service": "apigateway.amazonaws.com"

      },

      "Action": "sts:AssumeRole"

    }

  ]

}


Next, go to API Gateway --> create a REST API.


Create the folder & item resource

create GET --> 



with "tanldttestingapigateway" is a S3 bucket name.
/{folder}/{item} - GET - Method Execution --> to add URL path parameters
Create the folder "Test1" & upload one text file for testing purpose.




2 comments:

  1. Thank you for sharing these useful notes. If I wanted to get a an image, where and how can I get it? The body of response in your example can show the text but what about a .jpeg file?


    How do I put an image in the S3 bucket? where should I call the image from to be put into s3? using a put method?


    Thanks a lot

    ReplyDelete
    Replies
    1. Thank you for your comment.

      To get the image, I think it is the same but the body would be "binary". Sorry I did not develop to retrieve the image yet. Not sure for this one.

      To upload the image, you would use the "PUT" method.
      Below sample is uploaded pdf file. For image, I think you could change from .pdf to .jpeg
      E.g: curl --request PUT -H "Content-Type: application/pdf" --data-binary "@41032323221_04.pdf" https://xxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/41032323221.pdf

      Delete

Implemented a Service to receive real time message from an API Webhook

 What is the webhook?  Ask Google :) 😅  This is my experience to build a Azure Function HTTP trigger to receive an event from SkyBox API W...