How to consume an AWS API in c3?

I want to consume an AWS api in c3. Lets take an example.
I have a file in s3 and wanted to read file in c3 through api call.
file url: https://testBucket.s3.amazonaws.com/testFile.json

Please answer with an example.

Thanks

You can trying using the S3File API, example to read a file as a string do

curl -u $username:$password -v -H "Content-Type: application/json" \
  -X POST -d '{"this":{"url":"s3://testBucket/testFile.json"}}' \
  https://$environment/api/1/$tenant/$tag/S3File?action=readString

S3File.make([url]).readString()

1 Like

Thanks for the response. I was looking for different thing.
S3 Bucket is not mounted in c3. I want to make a call to AWS Restful API to read the content of the file which is available in S3. Call to API should happen within c3.

Sorry I was not clear before.

Thanks

HttpInvoker should be your best bet.
c3ShowType(HttpInvoker)

I did something like below to make rest provisioning calls from c3 to c3 :slight_smile:

var url = 'https://dev-poda.c3-e.com/api/1/c3/c3/Tenant?action=deploy';
     var httpRequest = {
       method: "POST",
       uri: url,
       headers: {
         "Content-Type": "application/json; charset=UTF-8",
         "Authorization": <authorization>
       },
       entity: JSON.stringify(spec)
     }
     try{
        var response = HttpInvoker.invoke(httpRequest, 60);        
     }
     catch(e){
       //
      }
2 Likes

Thank you for the response. I tried below thing.
HttpInvoker.invoke({uri:‘https://xxxxxx.s3.amazonaws.com/xxxxx.json’, method: ‘GET’, headers: {‘AccessKey’: ‘xxxxx’, ‘SecretKey’:‘xxxxx’, ‘AWS Region’:‘xxxxx’, ‘Service Name’: ‘s3’}}, 60)

But I am getting Access Denied

I tried with same above credentials from Postman but it worked well.

I am not sure what else I should do to make it work in c3.

Thanks

c3 will just invoke the rest call, not entirely sure what’s different with postman, can you check the header in the network tab on console and see if the request is sent correctly?
Access denied is aws throwing an exception, are the objects in your bucket public, is there more details in the error message?

I was able to find the issue and fix it.
AWS accepts the header in specific pattern. So we need to do little work before sending the request. below is the link that explains the details.
https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html

I am getting the content of the file into entity property of response object.
Example:
“entity” : “[{\r\n\t"primaryId”: “1”,\r\n\t"email": "raju@test.com",\r\n\t"timestamp": “Mar 16 08:12:04”\r\n},{\r\n\t"primaryId": “2”,\r\n\t"email": "micheal@test.com",\r\n\t"timestamp": “Mar 17 08:12:04”\r\n},{\r\n\t"primaryId": “3”,\r\n\t"email": "venkat@test.com",\r\n\t"timestamp": “Mar 18 08:12:04”\r\n}]"

This information is not readable. So I thought to create an entity and add it to the request for better readability and other purposes. But the documentation says “The entity body for the request. Required for POST and PUT; ignored by GET.”

So do we have any other option that I can assign data to the c3 type once we receive data from API.

Thanks

hmm, that is really tedious :slight_smile:
if you have the credentials can’t you get someone to just mount the s3 buckets for you, you code will be way cleaner/easier and you can focus on the downstream stuff.

But alternatively, if you check the type, mostly the response is received in a json of a type
c3ShowType(HttpResponse) structure.
And you can modify and play with the response as you please.
the details are in c3ShowType(HttpInvoker).

Hope that helps.