skip to Main Content

I am trying to create an api url with 2 params in Api gateway with lambda. I already tried with mapping query params and that is working fine but I want to add params in url. With one params its working fine but with 2 its showing error that Resource's path part only allow a-zA-Z0-9._-: or a valid greedy path variable and curly braces at the beginning and the end.

enter image description here

If i just use {userid+} that is working fine but I need to add 2 params

2

Answers


  1. Having a path-based parameter that contains + sign inside is called a greedy path, which means that the downstream integration of the endpoint will handle all request starting with the prefix of the path.

    eg. Consider a function with a greedy path defined as path: /horses/{proxy+}. This lambda function will handle all request that starts with /horses regarless of the depth of the sub-resource and its verb.

    Thus having the 2nd greedy path in a single URL is invalid.

    Perhaps you may wanna consider using a POST resource to handle a request that will accept a request body instead.

    path: /users
    method: POST
    

    You will then have to issue a POST request to it using popular libraries such as fetch

    const url = 'https://api.example.com/post-endpoint';
    const data = {
      username: 'foo-user',
      userID: 1
    };
    
    // Making the POST request using fetch
    const response = await fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json', // Set the content type to JSON
        // Add other headers if needed
      },
      body: JSON.stringify(data) // Convert data to JSON string
    })
    
    Login or Signup to reply.
  2. You can use greedy path parameter only at the end of the url.

    In your case just rename {userid+} to {userid}.

    You should have {userid}/{username+}

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search