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

AWS Cloud9 + API Gatewayで簡単API

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')"
}

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

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
ユーザーは見つかりませんでした