Last active
September 29, 2023 13:49
-
-
Save mryhryki/28fcd54e8a8cdffb78462d171ce48b27 to your computer and use it in GitHub Desktop.
curl の --aws-sigv4 オプションで AWS API にリクエストするサンプル(STSの一時的な認証情報を使用する場合)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# 情報ソース | |
# https://twitter.com/toricls/status/1435133865857667079 | |
# | |
# cURL --aws-sigv4 Option | |
# https://curl.se/docs/manpage.html#--aws-sigv4 | |
# | |
# AWS Lambda - ListFunctions API | |
# https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/API_ListFunctions.html | |
# | |
# タスク 4: HTTP リクエストに署名を追加する | |
# > ヘッダーまたはクエリ文字列パラメーターの名前は X-Amz-Security-Token で、 | |
# > その値はセッショントークン (一時的なセキュリティ認証情報を取得する際に AWS STS から受け取った文字列) です。 | |
# 一時的な認証情報を使う場合は X-Amz-Security-Token ヘッダーに AWS_SESSION_TOKEN の値を入れればOK | |
# https://docs.aws.amazon.com/ja_jp/general/latest/gr/sigv4-add-signature-to-request.html | |
REGION="ap-northeast-1" | |
SERVICE="lambda" | |
curl "https://${SERVICE}.${REGION}.amazonaws.com/2015-03-31/functions/" \ | |
--verbose \ | |
-H "X-Amz-Security-Token: ${AWS_SESSION_TOKEN}" \ | |
--aws-sigv4 "aws:amz:${REGION}:${SERVICE}" \ | |
--user "${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment