Runtime API with S3 configured as storage service

0
To expose images over a public url we have created a JA with a custom request handler. In this request handler we an entity based on the path in the URL. Once the entity is retreived we use the Core method getImage() to get the contents of the image. Following a simplyfied version of the code (This example does not work and is only for demo purpose...): @Override protected void processRequest(IMxRuntimeRequest req, IMxRuntimeResponse resp, String requestPath) throws Exception { HttpServletResponse response = resp.getHttpServletResponse(); IMendixObject entity = Core.retrieveXPathQueryEscaped(context, "//%s[%s='%s']", handler.getEntity(), "Name", params.get("Name")); InputStream inputStream = Core.getImage(context, iMendixObject, false); IOUtils.copy(inputStream, response.getOutputStream()); } With the default filestorage service this works fine. Only with `com.mendix.core.StorageService` configured as `com.mendix.storage.s3` we get the following error: Failed to serve GET books: com.mendix.systemwideinterfaces.MendixRuntimeException: com.amazonaws.services.s3.model.AmazonS3Exception: The specified key does not exist. (Service: Amazon S3; Status Code: 404; Error Code: NoSuchKey; Request ID: 0902549049DC04A4), S3 Extended Request ID: TP8V/SBl3/i2yPfQyubjeBNDj7t/QvCug/GZShAPu27LLS9cTMi83IZHykqZvjng/AoTrIhqM9I= This while the file does exist on S3. If anyone knows how to work around this issue that would be great.
asked
2 answers
1

Did you set up the right IAM role? You can try to see if your IAM user has the right permissions by using the AWS S3 CLI to see if you read and write files in the bucket.

To debug you could (temporarily !) grant the S3 Full Access role.

answered
1

I tried to reproduce this, buy it works as expected, both when deployed in a sandbox, and locally from the modeler (with s3 configured).

The reproduction is on github: https://github.com/ako/ApiConnector/blob/master/javasource/apiconnector/impl/ApiConnectorHandler.java#L219

Start the app, create a product, add an image, and then retrieve it using the following api: http://localhost:8080/api/product/{EAN}/image/{ImageId}

I've seen the error you are getting, but only if the image doesn't exist. Please note that when you change from localfilestorage to s3, the image are automatically uploaded to s3. So you will be getting the error you mentioned if you try to download the image from s3, when in fact you uploaded it to the local file storage.

answered