cancel
Showing results for 
Search instead for 
Did you mean: 

Uploading file to AWS S3 bucket via REST API

sunit_s
Participant
0 Kudos

Hi Experts

I want to use REST adapter to upload file in Amazon's AWS S3 bucket. I have the target URL and Developer guide suggests I should use Authentication header

Authorization: AWS AWSAccessKeyId:Signature

https://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html

I have AWS Access Key Id and AWS secret access key. Now I have to create signature based on these. The Signature element is the RFC 2104 HMAC-SHA1 of selected elements from the request. I understand that I have to use AWS Secret access key on some string generated from request elements like HTTP-Verb, Date, etc. I assume I have to write some JAVA code for it.

I came across this discussion in may 16.

https://archive.sap.com/discussions/thread/3855339

But its not AWS S3 and signature is passed via query string and not http header. Are there any advancements in PI REST adapter since above discussion. How best to generate signature and execute REST API call for AWS S3? Our version is sap pi 7.4 sp 12.

Regards

Sunit

Accepted Solutions (1)

Accepted Solutions (1)

Muniyappan
Active Contributor

I have recently done this similar integration with AWS S3 bucket. It worked with Rest adapter using header and body fashion.

First you better download the jar from below link and play with it plain java code.

https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-examples-using-sdks.html#sig-v4-examples-usin...

jar

https://s3.amazonaws.com/aws-java-sdk/samples/AWSS3SigV4JavaSamples.jar

You can try to run the method putS3Object which is being called in the main method. You will get to know how posting is happening. You can also test the service in Post man, it has all functionality you just have to feed the credentials and payload. It works get and put.

PutS3ObjectSample.putS3Object(bucketName, regionName, awsAccessKey, awsSecretKey);

GetS3ObjectSample.getS3Object(bucketName, regionName, awsAccessKey, awsSecretKey);

PresignedUrlSample.getPresignedUrlToS3Object(bucketName, regionName, awsAccessKey, awsSecretKey); PutS3ObjectChunkedSample.putS3ObjectChunked(bucketName, regionName, awsAccessKey, awsSecretKey);

instead of doing all these, if you can catch amazon API team, your job will be easy. you can ask them what is the header and body format for posting.

0 Kudos

Hi muniyappan.marasamy,

Could you please share across sample code to for put method.

Thanks.

Muniyappan
Active Contributor
0 Kudos

you will find the code in the jars. please download and add into your project and then check

Answers (3)

Answers (3)

poornimal_nathan
Explorer
0 Kudos
PRAGSMATIC
Participant
0 Kudos

I would use a local file allocation where S3 is mounted rather that fixing REST adapter to communicate with AWS S3.

sunit_s
Participant
0 Kudos

Thanks for your reply.

Looks like you are using AWS SDK.

Where exactly did you write the java code in Java mapping or Adapter Module in REST channel?

Regards

sunit_s
Participant
0 Kudos

We used AWS SDK and sample code mentioned by Muni M in transform method of Java mapping.

Regards

philippeaddor
Active Participant
0 Kudos

Hi Sunit, thanks for sharing the solution. I wonder: Why did you not write a module in the receiver adapter? In your solution, where does the receiver channel point to and what does it do, since the actual transmission is already done during mapping?

Regards,

Philippe

Muniyappan
Active Contributor
0 Kudos

My assumtion is that generating signatures,checksum, etc are done using mapping. and posting is done via Rest receiver adapter.

In SDK, posting is happneing once the method is called, but i guess that should be commented. make the method to generate the signatures and return, but not making a call to endpoint.

We can do the posting in java code itself, but that is not a best practise.

However i will wait for Sunit's reply