LoginSignup
2
2

More than 3 years have passed since last update.

AWS Cloud9 + API Gatewayで簡単API

Last updated at Posted at 2019-11-18

AWS cloud9でAPIを作成

今回はgoogle tts APIを叩いて
音声ファイルを返信するAPIを作成します
AWS lambdaを直接いじると npmパッケージが読み込まれずめんどくさいので
Could9越しに使うのが良さそうです
ソースコードはこちら
https://github.com/freddiefujiwara/aws-lambda-tts

仕様

Input

Parameter 説明
q 音声にしたい文字列 我是日本人
tl 対象言語コード zh-cn

Output

{
  "statusCode": 200,
  "body": "https://translate.google.com/translate_tts?ie=UTF-8&q=%E8%BF%99%E4%B8%AA%E5%BE%88%E5%A4%A7&tl=zh-cn&total=1&idx=0&textlen=4&tk=13583.433909&client=t&prev=input&ttsspeed=1"
}

こんな感じです

Cloud9

環境作成

image.png
image.png

下記を選択して"Next Step"
- Create a new instance for environment (EC2)
- t2.micro (1 GiB RAM + 1 vCPU)
- Amazon Linux

最後はCreate Environment を押下
image.png

setup

image.png
↑の部分で

$ git clone https://github.com/freddiefujiwara/aws-lambda-tts.git
$ rm -rf /home/ec2-user/environment/tts/tts
$ mv aws-lambda-tts /home/ec2-user/environment/tts/tts
$ cd /home/ec2-user/environment/tts/tts
$ npm i

deploy

image.png

lambdaコンソールで確認

image.png
image.png

API Gatewayと接続

https://qiita.com/vankobe/items/ab5bc6487c7e07cb3aba
をみて接続しましょう
ちなみに このAPIの場合
image.png

こんな感じ Mapping Templatesの設定は下記です

#set($inputRoot=$input.path('$'))
{
  "q": "$input.params('q')",
  "tl": "$input.params('tl')"
}

すごく雑な説明ですが、個人的なメモとして

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2