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 回答
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
专家
已回答 10 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则