Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS API Gateway Resources #2

Open
georgeoffley opened this issue Jan 8, 2023 · 1 comment
Open

AWS API Gateway Resources #2

georgeoffley opened this issue Jan 8, 2023 · 1 comment

Comments

@georgeoffley
Copy link
Owner

georgeoffley commented Jan 8, 2023


title: AWS API Gateway Resources
subtitle:
description:
slug: aws-api-gateway-resources
tags: [note, aws]
category: dev-blog
image:
date: 2023-01-07
canonical: https://georgeoffley.com/aws-api-gateway-resources

TL;DR

Amazon API Gateway only allows for one path variable per resource. So these endpoints work:

  • <url>/user/{id}/update-status
  • <url>/user/{id}/search-user

These will throw an error since I already have the id as a path variable, and trying to set another is a Nah dawg.

  • <url>/user/{id}/update-status
  • <url>/user/{id}/search-user
  • <url>/user/{status}

The error is this:

An error occurred: ApiGatewayResourceChecksIdVar - A sibling ({id}) of this resource already has a variable path part -- only one is allowed.

More Context

So today, while charging full speed into a deliverable deadline, I spent an hour tracking down why my deployment to AWS kept failing. So, for some context, I'm making API endpoints for an internal tool at work.

So to work, I wrote the Cloudformation files for the new feature I was adding, only to run into an error with my deployment.

In my case, we had a resource for /user with a bunch of endpoints under it. Like so:

  • <url>/user/{id}/update-status
  • <url>/user/{id}/search-user

If you notice the {id} in those endpoints, those are path variables. These let us pass information into the API call. In the case above, we use them to pass in a user's ID to know which user to perform an action.

For this new feature I was working on, I needed to add the ability to create users with a specific user-status; my solution was to make an endpoint where the user-status was passed in via a path variable. Like so:

<url>/user/{status}

The Problem

API Gateway didn't like that one bit and threw this error when I deployed:

An error occurred: ApiGatewayResourceChecksIdVar - A sibling ({id}) of this resource already has a variable path part -- only one is allowed.

It turns out API Gateway only allows one path variable per resource, and my user resource already had the id path variable, so API Gateway threw an error when trying to set another.

Figuring It Out

This problem was easily solvable since it was a POST endpoint, and I would send a body of JSON data to it. So my solution was to add the status to the request payload. I know a little more about API Gateway; hopefully, you do too!

-George

@georgeoffley georgeoffley self-assigned this Jan 8, 2023
@swyxio
Copy link

swyxio commented Jan 9, 2023

nice note!

@georgeoffley georgeoffley changed the title ~AWS API Gateway Resources AWS API Gateway Resources Jan 11, 2023
@georgeoffley georgeoffley removed their assignment Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants