An open API service indexing awesome lists of open source software.

https://github.com/heiwa4126/sam-http-api1

AWS API Gateway の HTTP API の最小サンプルを AWS SAMで
https://github.com/heiwa4126/sam-http-api1

aws-gateway-api aws-sam example

Last synced: 7 months ago
JSON representation

AWS API Gateway の HTTP API の最小サンプルを AWS SAMで

Awesome Lists containing this project

README

          

# sam-http-api1

AWS API GatewayのHTTP APIの最小サンプルを AWS SAMで。

もとはSAMのhello worldテンプレートで(Python 3.9)、
変更したのは

- AWS::Serverless::Function の Events の Type を Api から HttpApi へ変更
- Outputs の HelloWorldApi の
- ServerlessRestApi を ServerlessHttpApi へ変更
- /Prod を削除 (ステージがデフォルト1個しかないみたい)。
- 最後の/を削除

# デプロイ

デプロイは普通に
`sam build && sam deploy --guided`
で。

```
HelloWorldFunction may not have authorization defined, Is this okay? [y/N]:
```

だけ `y`で(次のバージョンでJWTオーソライザーをつける予定)、
他はデフォルトで。

# 注意点

HTTP APIをサポートしていないリージョンがある(大阪とか)。

AWSコンソールのスタックのリソースの AWS::ApiGatewayV2::Api からのリンクが壊れている。
Lambdaのほうから回れば行ける。

レスポンスのContent-Typeが text/plain 。REST APIのほうはMIMEがJSONだったような気がする。

# 参考リンク

- [AWS::Serverless::HttpApi - AWS Serverless Application Model](https://docs.aws.amazon.com/ja_jp/serverless-application-model/latest/developerguide/sam-resource-httpapi.html#sam-resource-httpapi-return-values)
- [REST API と HTTP API 間で選択する - Amazon API Gateway](https://docs.aws.amazon.com/ja_jp/apigateway/latest/developerguide/http-api-vs-rest.html)
- [AWS SAMでHTTP APIを実装する。CORSも設定する。REST APIと微妙に違う! - Fusic Tech Blog](https://tech.fusic.co.jp/posts/2021-12-10-http-api-cors/)