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で
- Host: GitHub
- URL: https://github.com/heiwa4126/sam-http-api1
- Owner: heiwa4126
- Created: 2022-09-22T05:28:02.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-22T05:40:52.000Z (over 3 years ago)
- Last Synced: 2025-01-04T16:18:45.230Z (about 1 year ago)
- Topics: aws-gateway-api, aws-sam, example
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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/)