Help us understand the problem. What is going on with this article?

APIGatewayへのimportの話

More than 3 years have passed since last update.

API Gatewayの管理コンソールが新しくなってて、swaggerのインポートが簡単にできるようになっていました。4/5のアップデートですね。
これでaws-apigateway-importerを使わずに済む!

本家も公式行ってね、とアナウンスしておりますので、喜び勇んでCLIからインポートするように。
CLIを1.10.20に上げて、

>aws apigateway import-rest-api help

import-rest-api
^^^^^^^^^^^^^^^


Description
***********

A feature of the Amazon API Gateway control service for creating a new
API from an external API definition file.


Synopsis
********

     import-rest-api
   [--fail-on-warnings | --no-fail-on-warnings]
   [--parameters <value>]
   --body <value>
   [--cli-input-json <value>]
   [--generate-cli-skeleton]


Options
*******

"--fail-on-warnings" | "--no-fail-on-warnings" (boolean)

   A query parameter to indicate whether to rollback the API creation
   ("true" ) or not ("false" ) when a warning is encountered. The
   default value is "false" .

"--parameters" (map)

   Custom header parameters as part of the request.

Shorthand Syntax:

   KeyName1=string,KeyName2=string

JSON Syntax:

   {"string": "string"
     ...}

"--body" (blob)

   The POST request body containing external API definitions.
   Currently, only Swagger definition JSON files are supported.

"--cli-input-json" (string) Performs service operation based on the
JSON string provided. The JSON string follows the format provided by
"--generate-cli-skeleton". If other arguments are provided on the
command line, the CLI values will override the JSON-provided values.

"--generate-cli-skeleton" (boolean) Prints a sample input JSON to
standard output. Note the specified operation is not run if this
argument is specified. The sample input can be used as an argument for
"--cli-input-json".


Output
******

id -> (string)

   The API's identifier. This identifier is unique across all of your
   APIs in Amazon API Gateway.

name -> (string)

   The API's name.

description -> (string)

   The API's description.

createdDate -> (timestamp)

   The date when the API was created, in ISO 8601 format .

warnings -> (list)

   (string)

・・・あれ、jsonサポートのみ?yamlサポートしてないっすか?
仕方ない、yaml管理してたのをjsonに直して、、

aws apigateway import-rest-api --body test.json

A client error (BadRequestException) occurred when calling the ImportRestApi ope
ration: Invalid Swagger 2.0 input.

え?このjsonファイル、管理コンソールからだと通るんだけど、、、
教えて偉い人

ということで上記の通り、

aws apigateway import-rest-api --body file://test.json

ってしたらうまくいきました。
後はupdate-rest-apiとかput-rest-apiとか組み合わせればよいのね。

満足!

kurimoto
トレラン大好きエンジニア。
runners
スポーツで世界を良くしたいエンジニアチーム。応援navi、.finisher、run&といった製品開発をしています!
https://www.wantedly.com/projects/167082
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした