この記事で解決できる悩み
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
こんな悩みを解決できる記事を書きました!
僕は現役フリーランスエンジニア(歴8年)で、資格は13個保有しています。
結論、ChaliceでAPI GatewayにIAM認証を付けるのは超簡単です。
具体的なソースコードを載せているので安心してくださいね。
![](https://traveler0401.com/wp-content/uploads/2022/12/【AWS-Chalice】API-GatewayにIAM認証を付ける方法.jpg)
![](https://traveler0401.com/wp-content/uploads/2022/12/【AWS-Chalice】API-GatewayにIAM認証を付ける方法.jpg)
本記事を読めば、ChaliceでAPI GatewayにIAM認証を付ける方法が理解できるので早速見ていきましょう。
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
すぐ読み終わるので、ぜひ最後まで読んでくださいね♪
目次
ChaliceでAPI GatewayにIAM認証を付ける方法
早速ですが、ChaliceでAPI GatewayにIAM認証を付けてみます。
STEP
現状のAPI Gatewayを確認する
![](https://traveler0401.com/wp-content/uploads/2022/12/chalice_iam_authorization.png)
![](https://traveler0401.com/wp-content/uploads/2022/12/chalice_iam_authorization.png)
認可は「なし」に設定されています。
STEP
ChaliceにIAM認証を付与
from chalice import Chalice, IAMAuthorizer
app = Chalice(app_name='hello-world')
authorizer = IAMAuthorizer()
@app.route('/', methods=['GET'], authorizer=authorizer)
def index():
return {'hello': 'world'}
authorizerを設定することでIAM認証が付与されます。
STEP
デプロイする
$ chalice deploy
デプロイします。
STEP
再度、API Gatewayを確認する
![](https://traveler0401.com/wp-content/uploads/2022/12/chalice_iam_authorization2.png)
![](https://traveler0401.com/wp-content/uploads/2022/12/chalice_iam_authorization2.png)
AWS IAMが付与されていればOKです。
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
超簡単でしたね…
よくある質問
ChaliceでAPI GatewayにIAM認証を付けるにはどうすればよいですか?
authorizerを設定すればOKです。
詳しくは先ほどのソースコードをご確認ください。
Chaliceをローカルで起動した場合はどうなりますか?
ローカル起動した場合、認証は無視されます。
ですので、直接APIを実行しても認証エラーにはなりません。
ローカルで認証付きAPIを実行した場合のログ
/usr/local/lib/python3.9/site-packages/chalice/local.py:352:
UserWarning: IAMAuthorizer is not a supported in local mode.
All requests made against a route will be authorized to allow local testing.
Cognito認証を付ける方法を教えてもらえますか?
下記をご覧ください。
Congito認証はこちら!
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://traveler0401.com/wp-content/uploads/2022/12/aws-chalice-cognito-authorization-300x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/12/aws-chalice-cognito-authorization-300x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/12/aws-chalice-cognito-authorization-300x150.png)
【AWS Chalice】API GatewayにCognito認証を付ける方法
この記事で解決できる悩み ChaliceでAPI GatewayにCognito認証を付ける方法は? 結論、ChaliceでAPI GatewayにCognito認証を付けるのは超簡単です。 具体的なソースコー…
カスタムオーソライザーを付ける方法を教えてもらえますか?
下記をご覧ください。
カスタムオーソライザーはこちら!
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://traveler0401.com/wp-content/uploads/2022/12/aws-chalice-custom-authorization-300x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/12/aws-chalice-custom-authorization-300x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/12/aws-chalice-custom-authorization-300x150.png)
【AWS Chalice】カスタムオーソライザーを設定する方法
この記事で解決できる悩み Chaliceでカスタムオーソライザーを設定する方法は? 結論、Chaliceでカスタムオーソライザーを設定するのは超簡単です。 具体的なソースコー…
IAM認証を突破する方法を教えてもらえませんか?
下記をご覧ください。
IAM認証を突破する方法はこちら!
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://traveler0401.com/wp-content/uploads/2022/12/python-id-pool-api-gateway-300x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/12/python-id-pool-api-gateway-300x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/12/python-id-pool-api-gateway-300x150.png)
【Python】ID PoolでAPI GatewayのIAM認証を突破する方法
この記事で解決できる悩み ID PoolでAPI GatewayのIAM認証を突破する方法は? 結論、CognitoのID Poolを使ってAPI GatewayのIAM認証を突破するのは非常に簡単です。 具…
公式ドキュメントはありますか?
下記になります。
まとめ
今回は、ChaliceでAPI GatewayにIAM認証を付ける方法について解説しました。
以下が本記事のまとめになります。
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
最後までお読みいただき、ありがとうございました!
- クソおすすめ本
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
![](https://traveler0401.com/wp-content/uploads/2022/11/izumi-200-150x150.png)
海外のエンジニアがどういった思考で働いているかが理解できます。
海外に行く気はないけど海外エンジニアの動向が気になる雑魚エンジニアにおすすめです(本当におすすめな本しか紹介しないのでご安心を)。