Closed kokoichi206 closed 2 years ago
US-East-1 (バージニア北部) リージョン (us-east-1) にいることを確認します。Lambda@Edge 関数を作成するには、このリージョンに設定されている必要があります。
Edge へのデプロイ手順は、ほぼ通常と同じ?
ラインタイムは Node.js または Python
バケットポリシー
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::BUCKET_NAME/*"
}
]
}
環境変数はサポートされていません。
『Cloud Front > ビヘイビアを編集』
から関連付けなし、にする
module "lambda" {
source = "./modules/lambda"
prefix = var.prefix
table-arn = module.dynamodb.employee_list_table.arn
table-name = module.dynamodb.employee_list_table.name
providers = {
aws = aws.virginia
}
}
count = var.enable_custom_lambda ? 1 : 0
こんな書き方もできるのか
503 ERROR
The request could not be satisfied.
The Lambda function associated with the CloudFront distribution is invalid or doesn't have the required permissions. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
CloudWatch のログを見たらわかったが、DynamoDB に接続ができてなさそう。 どうやら、Edge が東京リージョンで実行されるのであれば、東京リージョンにラムダが必要そう(それはそうか)
The Lambda function returned an invalid entry in the headers object: Each header entry in the headers
そもそも Lambda with python で HTTP レスポンスの構築の仕方が違った。
queryParametersは渡ってきてなさそうだった!?!?!
lambda テストでの記載
{
"queryStringParameters": {
"name": "a0001"
}
}
url:
それはキャッシュ実行者(cloudfront)に聞くしかない。 クエリ文字列パラメータに基づくコンテンツのキャッシュ (AWS)を見る感じ、キャッシュには使われてそう。
terraform での設定が悪い?
resource "aws_cloudfront_distribution" "static-www" {
...
default_cache_behavior {
...
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
何をキャッシュさせるかを明示的に示してあげな
query_string_cache_keys
を使う。
この辺全体的にdeprecated
なのでcloudfront_cache_policy
にいつか変える。
思ったようにリダイレクトされないので、そもそもパラメータが受け取れいてるかを調べた(ラムダの中で event を出力し、cloudWatchLogs でチェックした)。
アクセスに使った URL: https://dpyf93zoqp8wf.cloudfront.net?name=a0001
{'Records': [{'cf': {'config': {'distributionDomainName': 'dpyf93zoqp8wf.cloudfront.net', 'distributionId': 'E15J5GRKZ1YFPB', 'eventType': 'viewer-request', 'requestId': 'PtKsIQehn79VnYHqLdI6LkzgjbAcd6_8vdbzONiLQZ7BlGMxTzqsPQ=='}, 'request': {'clientIp': '240f:74:c9f6:1:e49a:9d2b:41c4:697c', 'headers': {'host': [{'key': 'Host', 'value': 'dpyf93zoqp8wf.cloudfront.net'}], 'user-agent': [{'key': 'User-Agent', 'value': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'}], 'sec-ch-ua': [{'key': 'sec-ch-ua', 'value': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"'}], 'sec-ch-ua-mobile': [{'key': 'sec-ch-ua-mobile', 'value': '?0'}], 'sec-ch-ua-platform': [{'key': 'sec-ch-ua-platform', 'value': '"macOS"'}], 'upgrade-insecure-requests': [{'key': 'upgrade-insecure-requests', 'value': '1'}], 'accept': [{'key': 'accept', 'value': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'}], 'sec-fetch-site': [{'key': 'sec-fetch-site', 'value': 'cross-site'}], 'sec-fetch-mode': [{'key': 'sec-fetch-mode', 'value': 'navigate'}], 'sec-fetch-user': [{'key': 'sec-fetch-user', 'value': '?1'}], 'sec-fetch-dest': [{'key': 'sec-fetch-dest', 'value': 'document'}], 'referer': [{'key': 'referer', 'value': 'https://github.com/kokoichi206/cloud-prac/issues/5'}], 'accept-encoding': [{'key': 'accept-encoding', 'value': 'gzip, deflate, br'}], 'accept-language': [{'key': 'accept-language', 'value': 'ja,en-US;q=0.9,en;q=0.8'}]}, 'method': 'GET', 'querystring': 'name=a0001', 'uri': '/'}}}]}
querystring に値が入ってきてそうだけど、これがキャッシュを有効にした時の影響なのかどうかは、要チェック!!! (query_string = false, cache_keys => なし、にして調べてみたい)
AWS-SAA でよくみる構成を作ってみるシリーズ