Skip to content

REST API to Upload JSON documents to S3 - "Invalid mapping expression parameter specified"

0

Hi,

I'm looking for help with AWS API Gateway.

Objective:

  1. Create an authenticated REST API endpoint to allow PUT of JSON saved as files to S3. (Webhook)
  2. Create a REST API endpoint to allow PUT of images & PDF as files to S3 (<1MB) (Webhool)

https://repost.aws/knowledge-center/api-gateway-upload-image-s3

I'm looking to avoid using Lamdas as they don't seem to be necessary for this. I'm running into issues following all of these tutorials when it comes to configuring the API.

I notice a difference in the tutorial when creating the resources

Enter image description here

Create resources for your API

  1. In the Resources panel of your API page, select /.
  2. For Actions, choose Create Resource.
  3. For Resource Name, enter folder.
  4. For Resource Path, enter {folder}.
  5. Choose Create Resource.
  6. In the Resources panel, select the /{folder} resource that you created in step 5.
  7. Choose Actions, and then choose Create Resource.
  8. For Resource Name, enter object.
  9. For Resource Path, enter {object}.
  10. Choose Create Resource.

I created a folder resource with a object resource within it, but I can't put a a {folder} in the path as there is only a dropdown - can't enter custom text.

When continuing on and I get to this section, it doesn't want to accept the mapping parameters.

Configure parameter mappings for the PUT method

  1. In the Resources panel of your API page, choose PUT.
  2. Choose Integration Request.
  3. Expand URL Path Parameters.
  4. Choose Add path.
  5. For Name, enter bucket.
  6. For Mapped from, enter method.request.path.folder.
  7. Choose the check mark icon at the end of the row.
  8. Repeat steps 4–7. In step 5, set Name to key. In step 6, set Mapped from to method.request.path.object.

When I try and do the mapping's I get this error when trying to map bucket and key:

Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression parameter specified: method.request.path.object].

I've experienced this same issue when following 3 different tutorials?

It looks like something has changed since these tutorials were released and I can't seem to resolve the issue. Any help would be appreciated.

Also - the tutorial is mostly for handling binary file formats, can you also let me know what needs to differ to accept a JSON body and create JSON text files with .json extension in S3.

1 Answer
0

Hello,

https://repost.aws/knowledge-center/api-gateway-upload-image-s3 was updated one year ago, the steps here may be the way to operate on older consoles.

For steps based on the new console creation, you can refer to Tutorial: Create a REST API as an Amazon S3 proxy, for example:

To create an API resource that exposes the Amazon S3 service features

In the same AWS Region you created your Amazon S3 bucket, create an API named MyS3. This API's root resource (/) represents the Amazon S3 service. In this step, you create two additional resources /{folder} and /{item}.

  1. Choose Create resource.
  2. Keep Proxy resource turned off.
  3. For Resource path, select /.
  4. For Resource name, enter {folder}.
  5. Keep CORS (Cross Origin Resource Sharing) unchecked.
  6. Choose Create resource.
  7. Select the /{folder} resource, and then choose Create resource.
  8. Use the previous steps to create a child resource of /{folder} named {item}.

Your final API should look similar to the following: Declare method response types

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.