REST API created from swagger definition throws Forbidden error when invoking GET operation

0

I am using this command to import a REST API from a swagger file definition

aws apigateway import-rest-api --body fileb://pet-store-api-v2.json

The output I got is as follows:

{
    "id": "API_ID",
    "name": "Simple PetStore V2 (AWS CLI)",
    "createdDate": "2023-07-25T20:29:52-06:00",
    "version": "2023-07-26T00:02:09Z",
    "apiKeySource": "HEADER",
    "endpointConfiguration": {
        "types": [
            "EDGE"
        ]
    },
    "disableExecuteApiEndpoint": false
}

Here is the swagger file content:

{
  "swagger": "2.0",
  "info": {
    "version": "2023-07-26T00:02:09Z",
    "title": "Simple PetStore V2 (AWS CLI)"
  },
  "host": "{API_ID}.execute-api.{REGION}.amazonaws.com",
  "basePath": "/test",
  "schemes": [
    "https"
  ],
  "paths": {
    "/pets": {
      "get": {
        "responses": {
          "200": {
            "description": "200 response"
          }
        }
      }
    },
    "/pets/{petId}": {
      "get": {
        "parameters": [
          {
            "name": "petId",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "200 response"
          }
        }
      }
    }
  }
}

Everything seems to work fine however when I launch a GET request the server sends a 403 Forbidden error code

https://{API_ID}.execute-api.{REGION}.amazonaws.com/pets
{
    "message": "Forbidden"
}

Do I need to perform additional steps in order to get my REST API completely functional?

1 Antwort
0

Hi,

Could you confirm that you have deployed your API by creating an API deployment and associating it with a stage? Additionally, do not forget to include the stage name in the URL that you use to invoke the API.

https://{restapi-id}.execute-api.{region}.amazonaws.com/{stageName}

profile picture
EXPERTE
beantwortet vor 10 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen