背景・目的
以前、API Gatewayについて整理しました。今回は、エッジ最適化とリージョンの違いを試してみました。
今回、下記の観点を確認します。
- レイテンシ
- ルーティング
- ヘッダー有無
- キャッシュ
まとめ
検証結果
項目 | リージョン | エッジ最適化 | 結果 |
---|---|---|---|
レイテンシ | 同一リージョンで優位 | グローバルに有利 | 大差なし。ただしエッジでは初回遅延 |
ルーティング | リージョン直結で安定 | POP依存 | エッジではPOPにアクセス |
ヘッダー情報 | 付与なし | x-cacheなど | あり |
キャッシュ | CloudFrontは付与されない(必要に応じて自前で構築) | デフォルトでAWS管理のCloudFrontが自動的に有効 | デフォルトでCFでは設定されない |
実践
上記の背景・まとめにあげた観点で検証します。
前提
今回、下記の環境で実装しました
- Mac
- Cursor
事前準備
-
GitHubにプロジェクトを作成します
% gh repo create apigw-endpoint-type-hands-on --public --clone ✓ Created repository XXXX/apigw-endpoint-type-hands-on on github.com https://github.com/XXXX/apigw-endpoint-type-hands-on % ls -l
-
Cursorのワークスペースに上記のプロジェクトを追加します
CloudFormationの作成
- templatesフォルダを作成します
共通のLambda関数
- lambda.yamlを作成します
AWSTemplateFormatVersion: '2010-09-09' Description: "Common Lambda function for all API Gateway endpoints hands-on" Resources: LambdaFunction: Type: AWS::Lambda::Function Properties: FunctionName: HelloFunction Handler: index.handler Role: !GetAtt LambdaExecutionRole.Arn Runtime: python3.12 Code: ZipFile: | import json def handler(event, context): try: print("Event:", json.dumps(event)) print("Context:", str(context)) return { 'statusCode': 200, 'headers': { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }, 'body': json.dumps({ 'message': 'Hello, from lambda', 'event': event }) } except Exception as e: print("Error:", str(e)) return { 'statusCode': 500, 'headers': { 'Content-Type': 'application/json' }, 'body': json.dumps({ 'error': str(e) }) } LambdaExecutionRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: - lambda.amazonaws.com Action: - sts:AssumeRole Policies: - PolicyName: LambdaLogs PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - logs:CreateLogGroup - logs:CreateLogStream - logs:PutLogEvents Resource: "arn:aws:logs:*:*:*" Outputs: LambdaFunctionArn: Description: "ARN of the deployed Lambda function" Value: !GetAtt LambdaFunction.Arn Export: Name: "LambdaFunctionArn"
- 実行します
% aws cloudformation deploy \ --stack-name lambda \ --template-file ./templates/lambda.yaml \ --capabilities CAPABILITY_NAMED_IAM \ --region ap-northeast-1 Waiting for changeset to be created.. Waiting for stack create/update to complete Successfully created/updated stack - lambda %
- できました
% aws cloudformation describe-stack-resources \ --stack-name lambda { "StackResources": [ { "StackName": "lambda", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXXX:stack/lambda/XXXXX-XXXXX-XXXXX-XXXXX-XXXXX", "LogicalResourceId": "LambdaExecutionRole", "PhysicalResourceId": "lambda-LambdaExecutionRole-XXXXX", "ResourceType": "AWS::IAM::Role", "Timestamp": "2025-07-13T02:59:28.395000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } }, { "StackName": "lambda", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXXX:stack/lambda/XXXXX-XXXXX-XXXXX-XXXXX-XXXXX", "LogicalResourceId": "LambdaFunction", "PhysicalResourceId": "HelloFunction", "ResourceType": "AWS::Lambda::Function", "Timestamp": "2025-07-13T02:59:39.284000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } } ] } %
Edge API Gatewayを構築
-
edge-api.yamlを作成します
AWSTemplateFormatVersion: '2010-09-09' Description: "Edge API Gateway for Lambda integration" Resources: EdgeApi: Type: AWS::ApiGateway::RestApi Properties: Name: EdgeApi EndpointConfiguration: Types: - EDGE RootResource: Type: AWS::ApiGateway::Resource Properties: RestApiId: !Ref EdgeApi ParentId: !GetAtt EdgeApi.RootResourceId PathPart: test EdgeApiMethod: Type: AWS::ApiGateway::Method Properties: AuthorizationType: NONE HttpMethod: GET ResourceId: !Ref RootResource RestApiId: !Ref EdgeApi Integration: Type: AWS_PROXY IntegrationHttpMethod: POST Uri: !Sub - arn:aws:apigateway:${Region}:lambda:path/2015-03-31/functions/${LambdaArn}/invocations - Region: !Ref "AWS::Region" LambdaArn: !ImportValue LambdaFunctionArn EdgeApiDeployment: Type: AWS::ApiGateway::Deployment DependsOn: EdgeApiMethod Properties: RestApiId: !Ref EdgeApi StageName: test LambdaPermission: Type: AWS::Lambda::Permission Properties: FunctionName: !ImportValue LambdaFunctionArn Principal: apigateway.amazonaws.com Action: lambda:InvokeFunction SourceArn: !Sub - "arn:aws:execute-api:${Region}:${Account}:${EdgeApiId}/*/*/test" - Region: !Ref "AWS::Region" Account: !Ref "AWS::AccountId" EdgeApiId: !Ref EdgeApi Outputs: EdgeApiInvokeAPI: Description: "Invoke URL for Edge API" Value: !Sub - "https://${EdgeApi}.execute-api.${Region}.amazonaws.com/test/test" - EdgeApi: !Ref EdgeApi Region: !Ref "AWS::Region" Export: Name: EdgeApiInvokeAPI
-
デプロイします
% aws cloudformation deploy \ --stack-name edge-api \ --template-file ./templates/edge-api.yaml \ --capabilities CAPABILITY_NAMED_IAM \ --region ap-northeast-1 Waiting for changeset to be created.. Waiting for stack create/update to complete Successfully created/updated stack - edge-api %
-
できました
% aws cloudformation describe-stack-resources \ --stack-name edge-api { "StackResources": [ { "StackName": "edge-api", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXXX:stack/edge-api/XXXXX", "LogicalResourceId": "EdgeApi", "PhysicalResourceId": "XXXXX", "ResourceType": "AWS::ApiGateway::RestApi", "Timestamp": "2025-07-13T04:52:31.136000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } }, { "StackName": "edge-api", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXXX:stack/edge-api/XXXXX", "LogicalResourceId": "EdgeApiDeployment", "PhysicalResourceId": "XXXXX", "ResourceType": "AWS::ApiGateway::Deployment", "Timestamp": "2025-07-13T04:52:39.865000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } }, { "StackName": "edge-api", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXXX:stack/edge-api/XXXXX", "LogicalResourceId": "EdgeApiMethod", "PhysicalResourceId": "XXXXX|XXXXX|GET", "ResourceType": "AWS::ApiGateway::Method", "Timestamp": "2025-07-13T04:52:37.136000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } }, { "StackName": "edge-api", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXXX:stack/edge-api/XXXXX", "LogicalResourceId": "LambdaPermission", "PhysicalResourceId": "edge-api-LambdaPermission-XXXXX", "ResourceType": "AWS::Lambda::Permission", "Timestamp": "2025-07-13T04:52:33.397000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } }, { "StackName": "edge-api", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXXX:stack/edge-api/XXXXX", "LogicalResourceId": "RootResource", "PhysicalResourceId": "XXXXX", "ResourceType": "AWS::ApiGateway::Resource", "Timestamp": "2025-07-13T04:52:33.727000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } } ] } %
リージョン API Gatewayを構築
- regional-api.yamlを作成します
AWSTemplateFormatVersion: '2010-09-09' Description: "Regional API Gateway for Lambda integration" Resources: RegionalApi: Type: AWS::ApiGateway::RestApi Properties: Name: RegionalApi EndpointConfiguration: Types: - REGIONAL RootResource: Type: AWS::ApiGateway::Resource Properties: RestApiId: !Ref RegionalApi ParentId: !GetAtt RegionalApi.RootResourceId PathPart: test RegionalApiMethod: Type: AWS::ApiGateway::Method Properties: AuthorizationType: NONE HttpMethod: GET ResourceId: !Ref RootResource RestApiId: !Ref RegionalApi Integration: Type: AWS_PROXY IntegrationHttpMethod: POST Uri: !Sub - arn:aws:apigateway:${Region}:lambda:path/2015-03-31/functions/${LambdaFunctionArn}/invocations - Region: !Ref "AWS::Region" LambdaFunctionArn: !ImportValue LambdaFunctionArn LambdaPermissionRegional: Type: AWS::Lambda::Permission Properties: FunctionName: !ImportValue LambdaFunctionArn Principal: apigateway.amazonaws.com Action: lambda:InvokeFunction SourceArn: !Sub - "arn:aws:execute-api:${Region}:${Account}:${RegionalApiId}/*/*/test" - Region: !Ref "AWS::Region" Account: !Ref "AWS::AccountId" RegionalApiId: !Ref RegionalApi RegionalDeployment: Type: AWS::ApiGateway::Deployment DependsOn: RegionalApiMethod Properties: RestApiId: !Ref RegionalApi StageName: test Outputs: RegionalApiInvokeAPI: Description: "Invoke URL for Regional API" Value: !Sub - "https://${RegionalApi}.execute-api.${AWSRegion}.amazonaws.com/test/test" - RegionalApi: !Ref RegionalApi AWSRegion: !Ref "AWS::Region" Export: Name: RegionalApiInvokeAPI
- デプロイします
% aws cloudformation deploy \ --stack-name regional-api \ --template-file ./templates/regional-api.yaml \ --capabilities CAPABILITY_NAMED_IAM \ --region ap-northeast-1 Waiting for changeset to be created.. Waiting for stack create/update to complete Successfully created/updated stack - regional-api %
- できました
% aws cloudformation describe-stack-resources \ --stack-name edge-api { "StackResources": [ { "StackName": "edge-api", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXX:stack/edge-api/XXXX", "LogicalResourceId": "EdgeApi", "PhysicalResourceId": "XXXX", "ResourceType": "AWS::ApiGateway::RestApi", "Timestamp": "2025-07-13T04:52:31.136000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } }, { "StackName": "edge-api", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXX:stack/edge-api/XXXX", "LogicalResourceId": "EdgeApiDeployment", "PhysicalResourceId": "XXXX", "ResourceType": "AWS::ApiGateway::Deployment", "Timestamp": "2025-07-13T04:52:39.865000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } }, { "StackName": "edge-api", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXX:stack/edge-api/XXXX", "LogicalResourceId": "EdgeApiMethod", "PhysicalResourceId": "XXXX|XXXX|GET", "ResourceType": "AWS::ApiGateway::Method", "Timestamp": "2025-07-13T04:52:37.136000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } }, { "StackName": "edge-api", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXX:stack/edge-api/XXXX", "LogicalResourceId": "LambdaPermission", "PhysicalResourceId": "edge-api-LambdaPermission-XXXX", "ResourceType": "AWS::Lambda::Permission", "Timestamp": "2025-07-13T04:52:33.397000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } }, { "StackName": "edge-api", "StackId": "arn:aws:cloudformation:ap-northeast-1:XXXX:stack/edge-api/XXXX", "LogicalResourceId": "RootResource", "PhysicalResourceId": "XXXX", "ResourceType": "AWS::ApiGateway::Resource", "Timestamp": "2025-07-13T04:52:33.727000+00:00", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" } } ] } %
API Gatewayの確認
疎通
Edge API
- curlでアクセスします。できました
curl https://$EDGE_API_ID.execute-api.ap-northeast-1.amazonaws.com/test/test | jq { "message": "Hello, from lambda", ・・・ }
Regional API
- curlでアクセスします。できました
curl https://$REGIONA_API_ID.execute-api.ap-northeast-1.amazonaws.com/test/test | jq { "message": "Hello, from lambda", ・・・ }
検証
レイテンシー
- 下記のコマンドでテンプレートを作成します
cat <<EOF > curl-format.txt \n time_namelookup: %{time_namelookup}\n time_connect: %{time_connect}\n time_appconnect: %{time_appconnect}\n time_pretransfer: %{time_pretransfer}\n time_starttransfer: %{time_starttransfer}\n -------------------------\n total: %{time_total}\n EOF
Edge API
- 10回程度実行します
% for i in `seq 10`;do echo #$i:;curl -w "@curl-format.txt" -o /dev/null -s https://$EDGE_API_ID.execute-api.ap-northeast-1.amazonaws.com/test/test ;done; #1: time_namelookup: 0.023741 time_connect: 0.033874 time_appconnect: 0.071199 time_pretransfer: 0.071466 time_starttransfer: 0.121225 ------------------------- total: 0.121817 #2: time_namelookup: 0.005083 time_connect: 0.017197 time_appconnect: 0.027430 time_pretransfer: 0.027533 time_starttransfer: 0.064453 ------------------------- total: 0.065275 #3: time_namelookup: 0.005090 time_connect: 0.015517 time_appconnect: 0.025505 time_pretransfer: 0.025611 time_starttransfer: 0.062711 ------------------------- total: 0.063537 #4: time_namelookup: 0.003430 time_connect: 0.014812 time_appconnect: 0.023849 time_pretransfer: 0.023953 time_starttransfer: 0.082301 ------------------------- total: 0.083142 #5: time_namelookup: 0.003603 time_connect: 0.016525 time_appconnect: 0.027852 time_pretransfer: 0.028014 time_starttransfer: 0.061036 ------------------------- total: 0.061631 #6: time_namelookup: 0.003876 time_connect: 0.014804 time_appconnect: 0.026991 time_pretransfer: 0.027099 time_starttransfer: 0.056700 ------------------------- total: 0.057456 #7: time_namelookup: 0.003372 time_connect: 0.015703 time_appconnect: 0.027140 time_pretransfer: 0.027585 time_starttransfer: 0.058905 ------------------------- total: 0.059752 #8: time_namelookup: 0.003548 time_connect: 0.015044 time_appconnect: 0.027004 time_pretransfer: 0.027213 time_starttransfer: 0.055723 ------------------------- total: 0.056146 #9: time_namelookup: 0.003746 time_connect: 0.014235 time_appconnect: 0.023525 time_pretransfer: 0.023632 time_starttransfer: 0.054471 ------------------------- total: 0.054997 #10: time_namelookup: 0.003307 time_connect: 0.013392 time_appconnect: 0.022097 time_pretransfer: 0.022235 time_starttransfer: 0.055672 ------------------------- total: 0.056017 %
Regional API
- 10回程度実行します
% for i in `seq 10`;do echo #$i:;curl -w "@curl-format.txt" -o /dev/null -s https://$REGIONAL_API_ID.execute-api.ap-northeast-1.amazonaws.com/test/test ;done; #1: time_namelookup: 0.040283 time_connect: 0.047121 time_appconnect: 0.057232 time_pretransfer: 0.057485 time_starttransfer: 0.102093 ------------------------- total: 0.102888 #2: time_namelookup: 0.003619 time_connect: 0.015702 time_appconnect: 0.024364 time_pretransfer: 0.024494 time_starttransfer: 0.080021 ------------------------- total: 0.080994 #3: time_namelookup: 0.003977 time_connect: 0.015728 time_appconnect: 0.025135 time_pretransfer: 0.025242 time_starttransfer: 0.054204 ------------------------- total: 0.054545 #4: time_namelookup: 0.003929 time_connect: 0.014380 time_appconnect: 0.024267 time_pretransfer: 0.024464 time_starttransfer: 0.050963 ------------------------- total: 0.051327 #5: time_namelookup: 0.003331 time_connect: 0.013868 time_appconnect: 0.023049 time_pretransfer: 0.023282 time_starttransfer: 0.052919 ------------------------- total: 0.053483 #6: time_namelookup: 0.003247 time_connect: 0.013824 time_appconnect: 0.023769 time_pretransfer: 0.023907 time_starttransfer: 0.068096 ------------------------- total: 0.068865 #7: time_namelookup: 0.004652 time_connect: 0.014489 time_appconnect: 0.024241 time_pretransfer: 0.024346 time_starttransfer: 0.055318 ------------------------- total: 0.055618 #8: time_namelookup: 0.003009 time_connect: 0.012320 time_appconnect: 0.021666 time_pretransfer: 0.021851 time_starttransfer: 0.049902 ------------------------- total: 0.050481 #9: time_namelookup: 0.003232 time_connect: 0.013684 time_appconnect: 0.023354 time_pretransfer: 0.023463 time_starttransfer: 0.051446 ------------------------- total: 0.052043 #10: time_namelookup: 0.004090 time_connect: 0.013445 time_appconnect: 0.022953 time_pretransfer: 0.023090 time_starttransfer: 0.052216 ------------------------- total: 0.053085 %
比較結果
- 平均応答時間 Regional の方が若干速い(6msほど)
- まとめ
- Edge は初回にやや遅延あり、Regional は全体的に安定
- 東京リージョンからの実行においては、Regional API の方が一貫性があり高速だった。CloudFront の POP 利用による恩恵が今回の環境では見られなかった
ルーティングの確認
Edge API
- 10回程度実行します
% for i in `seq 10`;do echo #$i:; curl -X GET -I https://$EDGE_API_ID.execute-api.ap-northeast-1.amazonaws.com/test/test;done #1: HTTP/2 200 content-type: application/json content-length: 2542 date: Sun, 13 Jul 2025 06:07:28 GMT x-amzn-trace-id: Root=1-xxxx;Parent=xxxx;Sampled=0;Lineage=1:8d3a6eed:0 x-amzn-requestid: xxxx access-control-allow-origin: * x-amz-apigw-id: xxxx x-cache: Miss from cloudfront via: 1.1 xxxx.cloudfront.net (CloudFront) x-amz-cf-pop: NRT12-P4 x-amz-cf-id: xxxx #2: HTTP/2 200 content-type: application/json content-length: 2542 date: Sun, 13 Jul 2025 06:07:29 GMT x-amzn-trace-id: Root=1-xxxx;Sampled=0;Lineage=1:8d3a6eed:0 x-amzn-requestid: xxxx access-control-allow-origin: * x-amz-apigw-id: xxxx x-cache: Miss from cloudfront via: 1.1 xxxx.cloudfront.net (CloudFront) x-amz-cf-pop: NRT12-P4 x-amz-cf-id: xxxx #3: HTTP/2 200 content-type: application/json content-length: 2542 date: Sun, 13 Jul 2025 06:07:29 GMT x-amzn-trace-id: Root=xxxx;Parent=xxxx;Sampled=0;Lineage=1:8d3a6eed:0 x-amzn-requestid: xxxx access-control-allow-origin: * x-amz-apigw-id: xxxx x-cache: Miss from cloudfront via: 1.1 xxxx.cloudfront.net (CloudFront) x-amz-cf-pop: NRT12-P4 x-amz-cf-id: xxxx #4: HTTP/2 200 content-type: application/json content-length: 2542 date: Sun, 13 Jul 2025 06:07:29 GMT x-amzn-trace-id: Root=xxxx;Parent=xxxx;Sampled=0;Lineage=1:8d3a6eed:0 x-amzn-requestid: xxxx access-control-allow-origin: * x-amz-apigw-id: xxxx x-cache: Miss from cloudfront via: 1.1 xxxx.cloudfront.net (CloudFront) x-amz-cf-pop: NRT12-P4 x-amz-cf-id: xxxx #5: HTTP/2 200 content-type: application/json content-length: 2542 date: Sun, 13 Jul 2025 06:07:29 GMT x-amzn-trace-id: Root=xxxx;Parent=xxxx;Sampled=0;Lineage=1:8d3a6eed:0 x-amzn-requestid: xxxx access-control-allow-origin: * x-amz-apigw-id: xxxx x-cache: Miss from cloudfront via: 1.1 xxxx.cloudfront.net (CloudFront) x-amz-cf-pop: NRT12-P4 x-amz-cf-id: xxxx #6: HTTP/2 200 content-type: application/json content-length: 2542 date: Sun, 13 Jul 2025 06:07:29 GMT x-amzn-trace-id: Root=xxxx;Parent=xxxx;Sampled=0;Lineage=1:8d3a6eed:0 x-amzn-requestid: xxxx access-control-allow-origin: * x-amz-apigw-id: xxxx x-cache: Miss from cloudfront via: 1.1 xxxx.cloudfront.net (CloudFront) x-amz-cf-pop: NRT12-P4 x-amz-cf-id: xxxx #7: HTTP/2 200 content-type: application/json content-length: 2542 date: Sun, 13 Jul 2025 06:07:29 GMT x-amzn-trace-id: Root=xxxx;Parent=xxxx;Sampled=0;Lineage=1:8d3a6eed:0 x-amzn-requestid: xxxx access-control-allow-origin: * x-amz-apigw-id: xxxx x-cache: Miss from cloudfront via: 1.1 xxxx.cloudfront.net (CloudFront) x-amz-cf-pop: NRT12-P4 x-amz-cf-id: xxxx-WVzGFXqA== #8: HTTP/2 200 content-type: application/json content-length: 2542 date: Sun, 13 Jul 2025 06:07:29 GMT x-amzn-trace-id: Root=xxxx;Parent=xxxx;Sampled=0;Lineage=1:8d3a6eed:0 x-amzn-requestid: xxxx access-control-allow-origin: * x-amz-apigw-id: xxxx x-cache: Miss from cloudfront via: 1.1 xxxx.cloudfront.net (CloudFront) x-amz-cf-pop: NRT12-P4 x-amz-cf-id: xxxx #9: HTTP/2 200 content-type: application/json content-length: 2542 date: Sun, 13 Jul 2025 06:07:29 GMT x-amzn-trace-id: Root=xxxx;Parent=xxxx;Sampled=0;Lineage=1:8d3a6eed:0 x-amzn-requestid: xxxx access-control-allow-origin: * x-amz-apigw-id: xxxx x-cache: Miss from cloudfront via: 1.1 xxxx.cloudfront.net (CloudFront) x-amz-cf-pop: NRT12-P4 x-amz-cf-id: xxxx #10: HTTP/2 200 content-type: application/json content-length: 2542 date: Sun, 13 Jul 2025 06:07:29 GMT x-amzn-trace-id: Root=xxxx;Parent=xxxx;Sampled=0;Lineage=1:8d3a6eed:0 x-amzn-requestid: xxxx access-control-allow-origin: * x-amz-apigw-id: xxxx x-cache: Miss from cloudfront via: 1.1 xxxx.cloudfront.net (CloudFront) x-amz-cf-pop: NRT12-P4 x-amz-cf-id: xxxx %
Regional API
- 10回程度実行します
% for i in `seq 10`;do echo #$i:; curl -X GET -I https://$REGIONAL_API_ID.execute-api.ap-northeast-1.amazonaws.com/test/test;done #1: HTTP/2 200 date: Sun, 13 Jul 2025 06:15:20 GMT content-type: application/json content-length: 1662 x-amzn-requestid: XXXX access-control-allow-origin: * x-amz-apigw-id: XXXX x-amzn-trace-id: Root=XXXX;Parent=XXXX;Sampled=0;Lineage=1:8d3a6eed:0 #2: HTTP/2 200 date: Sun, 13 Jul 2025 06:15:20 GMT content-type: application/json content-length: 1662 x-amzn-requestid: XXXX access-control-allow-origin: * x-amz-apigw-id: XXXX x-amzn-trace-id: Root=XXXX;Parent=XXXX;Sampled=0;Lineage=1:8d3a6eed:0 #3: HTTP/2 200 date: Sun, 13 Jul 2025 06:15:20 GMT content-type: application/json content-length: 1662 x-amzn-requestid: XXXX access-control-allow-origin: * x-amz-apigw-id: XXXX x-amzn-trace-id: Root=XXXX;Parent=XXXX;Sampled=0;Lineage=1:8d3a6eed:0 #4: HTTP/2 200 date: Sun, 13 Jul 2025 06:15:20 GMT content-type: application/json content-length: 1662 x-amzn-requestid: XXXX access-control-allow-origin: * x-amz-apigw-id: XXXX x-amzn-trace-id: Root=XXXX;Parent=XXXX;Sampled=0;Lineage=1:8d3a6eed:0 #5: HTTP/2 200 date: Sun, 13 Jul 2025 06:15:20 GMT content-type: application/json content-length: 1662 x-amzn-requestid: XXXX access-control-allow-origin: * x-amz-apigw-id: XXXX x-amzn-trace-id: Root=XXXX;Parent=XXXX;Sampled=0;Lineage=1:8d3a6eed:0 #6: HTTP/2 200 date: Sun, 13 Jul 2025 06:15:20 GMT content-type: application/json content-length: 1662 x-amzn-requestid: XXXX access-control-allow-origin: * x-amz-apigw-id: XXXX x-amzn-trace-id: Root=XXXX;Parent=XXXX;Sampled=0;Lineage=1:8d3a6eed:0 #7: HTTP/2 200 date: Sun, 13 Jul 2025 06:15:20 GMT content-type: application/json content-length: 1662 x-amzn-requestid: XXXX access-control-allow-origin: * x-amz-apigw-id: XXXX x-amzn-trace-id: Root=XXXX;Parent=XXXX;Sampled=0;Lineage=1:8d3a6eed:0 #8: HTTP/2 200 date: Sun, 13 Jul 2025 06:15:20 GMT content-type: application/json content-length: 1662 x-amzn-requestid: XXXX access-control-allow-origin: * x-amz-apigw-id: XXXX x-amzn-trace-id: Root=XXXX;Parent=XXXX;Sampled=0;Lineage=1:8d3a6eed:0 #9: HTTP/2 200 date: Sun, 13 Jul 2025 06:15:21 GMT content-type: application/json content-length: 1662 x-amzn-requestid: XXXX access-control-allow-origin: * x-amz-apigw-id: XXXX x-amzn-trace-id: Root=XXXX;Parent=XXXX;Sampled=0;Lineage=1:8d3a6eed:0 #10: HTTP/2 200 date: Sun, 13 Jul 2025 06:15:21 GMT content-type: application/json content-length: 1662 x-amzn-requestid: XXXX access-control-allow-origin: * x-amz-apigw-id: XXXX x-amzn-trace-id: Root=XXXX;Parent=XXXX;Sampled=0;Lineage=1:8d3a6eed:0 %
比較結果
- POP(Point of Presence)はRegional APIには使われていない
- x-amz-cf-popはなし。(Edgeにあり)
- キャッシュは、Regional APIには使われてない
- ただしEdgeには、x-cacheがあるがMiss from cloudfrontである
考察
今回、エッジ最適化エンドポイントとリージョンエンドポイントの違いについて検証しました。
エッジ最適化ならではの速度やPOP(Point of Presence)の違いは、今回は明確には確認できませんでしたが、レスポンスヘッダーの違いについては確認することができました。
今後これらを利用する際には、それぞれのエンドポイントタイプの挙動をより詳しく確認していきたいと思います。
参考