Boto3 + SSM Public Parameter でリージョンごとのサービスエンドポイント一覧を作ってみた

SSM の Public Parameter はいいぞ。
2020.07.01

コンサルティング部の西野です。
Boto3 + SSM Public Parameter でリージョンごとのサービスエンドポイントを一覧化してみました。

やりたいこと

サービス エンドポイントとクォータ のページには AWS のサービスがまとめられており、各サービスのページに飛ぶと下記形式のサービスエンドポイントを確認できます。

service-code.region-code.amazonaws.com

たとえば、Amazon EC2 のページには下のような表があります。

EC2 の場合、 service-code がec2であり、アジアパシフィック(東京)リージョンの場合 region-code がap-northeast-1というわけですね。

サービスごとのエンドポイントを確認したい場合はこのページを使えばいいのですが、リージョンカットでまとめられている公式ドキュメントは(おそらく)存在しません。
なので、作ってみました。

東京リージョンのサービスエンドポイント一覧

アジアパシフィック(東京)リージョンのサービスエンドポイント一覧は下記のとおりです。
※2020/07/01時点のものです。
※最新情報を取得したい場合には後述のスクリプトをご使用ください。

サービスコード サービスエンドポイント
accessanalyzer access-analyzer.ap-northeast-1.amazonaws.com
acm acm.ap-northeast-1.amazonaws.com
acm-pca acm-pca.ap-northeast-1.amazonaws.com
amplify amplify.ap-northeast-1.amazonaws.com
apigateway apigateway.ap-northeast-1.amazonaws.com
apigatewaymanagementapi execute-api.ap-northeast-1.amazonaws.com
apigatewayv2 apigateway.ap-northeast-1.amazonaws.com
appconfig appconfig.ap-northeast-1.amazonaws.com
application-autoscaling application-autoscaling.ap-northeast-1.amazonaws.com
application-insights applicationinsights.ap-northeast-1.amazonaws.com
appmesh appmesh.ap-northeast-1.amazonaws.com
appstream appstream2.ap-northeast-1.amazonaws.com
appsync appsync.ap-northeast-1.amazonaws.com
athena athena.ap-northeast-1.amazonaws.com
autoscaling autoscaling.ap-northeast-1.amazonaws.com
autoscaling-plans autoscaling-plans.ap-northeast-1.amazonaws.com
backup backup.ap-northeast-1.amazonaws.com
batch batch.ap-northeast-1.amazonaws.com
budgets budgets.amazonaws.com
chime chime.ap-northeast-1.amazonaws.com
cloud9 cloud9.ap-northeast-1.amazonaws.com
cloudformation cloudformation.ap-northeast-1.amazonaws.com
cloudfront cloudfront.amazonaws.com
cloudhsm cloudhsm.ap-northeast-1.amazonaws.com
cloudhsmv2 cloudhsmv2.ap-northeast-1.amazonaws.com
cloudsearch cloudsearch.ap-northeast-1.amazonaws.com
cloudtrail cloudtrail.ap-northeast-1.amazonaws.com
cloudwatch monitoring.ap-northeast-1.amazonaws.com
codeartifact codeartifact.ap-northeast-1.amazonaws.com
codebuild codebuild.ap-northeast-1.amazonaws.com
codecommit codecommit.ap-northeast-1.amazonaws.com
codedeploy codedeploy.ap-northeast-1.amazonaws.com
codeguru-reviewer codeguru-reviewer.ap-northeast-1.amazonaws.com
codeguruprofiler codeguru-profiler.ap-northeast-1.amazonaws.com
codepipeline codepipeline.ap-northeast-1.amazonaws.com
codestar codestar.ap-northeast-1.amazonaws.com
codestar-connections codestar-connections.ap-northeast-1.amazonaws.com
codestar-notifications codestar-notifications.ap-northeast-1.amazonaws.com
cognito-identity cognito-identity.ap-northeast-1.amazonaws.com
cognito-idp cognito-idp.ap-northeast-1.amazonaws.com
cognito-sync cognito-sync.ap-northeast-1.amazonaws.com
comprehend comprehend.ap-northeast-1.amazonaws.com
compute-optimizer compute-optimizer.ap-northeast-1.amazonaws.com
config config.ap-northeast-1.amazonaws.com
connect connect.ap-northeast-1.amazonaws.com
connectparticipant execute-api.ap-northeast-1.amazonaws.com
dataexchange dataexchange.ap-northeast-1.amazonaws.com
datapipeline datapipeline.ap-northeast-1.amazonaws.com
datasync datasync.ap-northeast-1.amazonaws.com
dax dax.ap-northeast-1.amazonaws.com
detective api.detective.ap-northeast-1.amazonaws.com
directconnect directconnect.ap-northeast-1.amazonaws.com
discovery discovery.ap-northeast-1.amazonaws.com
dlm dlm.ap-northeast-1.amazonaws.com
dms dms.ap-northeast-1.amazonaws.com
docdb rds.ap-northeast-1.amazonaws.com
ds ds.ap-northeast-1.amazonaws.com
dynamodb dynamodb.ap-northeast-1.amazonaws.com
dynamodbstreams streams.dynamodb.ap-northeast-1.amazonaws.com
ebs ec2.ap-northeast-1.amazonaws.com
ec2 ec2.ap-northeast-1.amazonaws.com
ecr ecr.ap-northeast-1.amazonaws.com
ecs ecs.ap-northeast-1.amazonaws.com
efs elasticfilesystem.ap-northeast-1.amazonaws.com
eks eks.ap-northeast-1.amazonaws.com
elastic-inference api.elastic-inference.ap-northeast-1.amazonaws.com
elasticache elasticache.ap-northeast-1.amazonaws.com
elasticbeanstalk elasticbeanstalk.ap-northeast-1.amazonaws.com
elastictranscoder elastictranscoder.ap-northeast-1.amazonaws.com
elb elasticloadbalancing.ap-northeast-1.amazonaws.com
emr elasticmapreduce.ap-northeast-1.amazonaws.com
es es.ap-northeast-1.amazonaws.com
events events.ap-northeast-1.amazonaws.com
firehose firehose.ap-northeast-1.amazonaws.com
fms fms.ap-northeast-1.amazonaws.com
forecast forecast.ap-northeast-1.amazonaws.com
forecastquery forecastquery.ap-northeast-1.amazonaws.com
fsx fsx.ap-northeast-1.amazonaws.com
gamelift gamelift.ap-northeast-1.amazonaws.com
glacier glacier.ap-northeast-1.amazonaws.com
globalaccelerator globalaccelerator.amazonaws.com
glue glue.ap-northeast-1.amazonaws.com
greengrass greengrass.ap-northeast-1.amazonaws.com
guardduty guardduty.ap-northeast-1.amazonaws.com
iam iam.amazonaws.com
imagebuilder imagebuilder.ap-northeast-1.amazonaws.com
inspector inspector.ap-northeast-1.amazonaws.com
iot iot.ap-northeast-1.amazonaws.com
iot-data data.iot.ap-northeast-1.amazonaws.com
iot1click-projects projects.iot1click.ap-northeast-1.amazonaws.com
iotanalytics iotanalytics.ap-northeast-1.amazonaws.com
iotevents iotevents.ap-northeast-1.amazonaws.com
iotevents-data data.iotevents.ap-northeast-1.amazonaws.com
iotthingsgraph iotthingsgraph.ap-northeast-1.amazonaws.com
kafka kafka.ap-northeast-1.amazonaws.com
kinesis kinesis.ap-northeast-1.amazonaws.com
kinesisanalytics kinesisanalytics.ap-northeast-1.amazonaws.com
kinesisvideo kinesisvideo.ap-northeast-1.amazonaws.com
kms kms.ap-northeast-1.amazonaws.com
lakeformation lakeformation.ap-northeast-1.amazonaws.com
lambda lambda.ap-northeast-1.amazonaws.com
lex-models models.lex.ap-northeast-1.amazonaws.com
lex-runtime runtime.lex.ap-northeast-1.amazonaws.com
license-manager license-manager.ap-northeast-1.amazonaws.com
lightsail lightsail.ap-northeast-1.amazonaws.com
logs logs.ap-northeast-1.amazonaws.com
macie2 macie2.ap-northeast-1.amazonaws.com
managedblockchain managedblockchain.ap-northeast-1.amazonaws.com
mediaconnect mediaconnect.ap-northeast-1.amazonaws.com
mediaconvert mediaconvert.ap-northeast-1.amazonaws.com
medialive medialive.ap-northeast-1.amazonaws.com
mediapackage mediapackage.ap-northeast-1.amazonaws.com
mediapackage-vod mediapackage-vod.ap-northeast-1.amazonaws.com
mediastore mediastore.ap-northeast-1.amazonaws.com
mediastore-data data.mediastore.ap-northeast-1.amazonaws.com
mediatailor api.mediatailor.ap-northeast-1.amazonaws.com
meteringmarketplace metering.marketplace.ap-northeast-1.amazonaws.com
mgh mgh.ap-northeast-1.amazonaws.com
mq mq.ap-northeast-1.amazonaws.com
neptune rds.ap-northeast-1.amazonaws.com
opsworks opsworks.ap-northeast-1.amazonaws.com
opsworkscm opsworks-cm.ap-northeast-1.amazonaws.com
organizations organizations.us-east-1.amazonaws.com
outposts outposts.ap-northeast-1.amazonaws.com
personalize personalize.ap-northeast-1.amazonaws.com
pi pi.ap-northeast-1.amazonaws.com
polly polly.ap-northeast-1.amazonaws.com
qldb qldb.ap-northeast-1.amazonaws.com
qldb-session session.qldb.ap-northeast-1.amazonaws.com
quicksight quicksight.ap-northeast-1.amazonaws.com
ram ram.ap-northeast-1.amazonaws.com
rds rds.ap-northeast-1.amazonaws.com
rds-data rds-data.ap-northeast-1.amazonaws.com
redshift redshift.ap-northeast-1.amazonaws.com
rekognition rekognition.ap-northeast-1.amazonaws.com
resource-groups resource-groups.ap-northeast-1.amazonaws.com
resourcegroupstaggingapi tagging.ap-northeast-1.amazonaws.com
robomaker robomaker.ap-northeast-1.amazonaws.com
route53 route53.amazonaws.com
route53resolver route53resolver.ap-northeast-1.amazonaws.com
s3 s3.ap-northeast-1.amazonaws.com
s3control s3-control.ap-northeast-1.amazonaws.com
sagemaker api.sagemaker.ap-northeast-1.amazonaws.com
sagemaker-runtime runtime.sagemaker.ap-northeast-1.amazonaws.com
savingsplans savingsplans.amazonaws.com
schemas schemas.ap-northeast-1.amazonaws.com
sdb sdb.ap-northeast-1.amazonaws.com
secretsmanager secretsmanager.ap-northeast-1.amazonaws.com
securityhub securityhub.ap-northeast-1.amazonaws.com
serverlessrepo serverlessrepo.ap-northeast-1.amazonaws.com
service-quotas servicequotas.ap-northeast-1.amazonaws.com
servicecatalog servicecatalog.ap-northeast-1.amazonaws.com
servicediscovery servicediscovery.ap-northeast-1.amazonaws.com
shield shield.us-east-1.amazonaws.com
signer signer.ap-northeast-1.amazonaws.com
sms sms.ap-northeast-1.amazonaws.com
snowball snowball.ap-northeast-1.amazonaws.com
sns sns.ap-northeast-1.amazonaws.com
sqs sqs.ap-northeast-1.amazonaws.com
ssm ssm.ap-northeast-1.amazonaws.com
stepfunctions states.ap-northeast-1.amazonaws.com
storagegateway storagegateway.ap-northeast-1.amazonaws.com
sts sts.ap-northeast-1.amazonaws.com
support support.us-east-1.amazonaws.com
swf swf.ap-northeast-1.amazonaws.com
synthetics synthetics.ap-northeast-1.amazonaws.com
transcribe transcribe.ap-northeast-1.amazonaws.com
transfer transfer.ap-northeast-1.amazonaws.com
translate translate.ap-northeast-1.amazonaws.com
waf waf.amazonaws.com
waf-regional waf-regional.ap-northeast-1.amazonaws.com
wafv2 wafv2.ap-northeast-1.amazonaws.com
workdocs workdocs.ap-northeast-1.amazonaws.com
workspaces workspaces.ap-northeast-1.amazonaws.com
xray xray.ap-northeast-1.amazonaws.com

サービスエンドポイント一覧の取得方法

  • Boto3 を使って SSM の Public Parameter から必要な値を取得しています。
  • REGION 変数の値を書き換えることで別リージョンにも対応可能です。
  • 上記表のもととなる csv ファイルがスクリプトと同じディレクトリに出力されます。
  • FIPS エンドポイントには非対応です。

service_endpoint.py

import csv
import boto3

REGION = 'ap-northeast-1'
CSV_FILENAME = '{}_endpoint.csv'.format(REGION)

def generate_services(response_iterator):
    services = []
    for page in response_iterator:
        for parameter in page['Parameters']:
            service = parameter['Value']
            services.append(service)
    services.sort()
    return services

def generate_endpoint_ssmpaths(services):
    endpoint_ssmpaths = []
    for service in services:
        endpoint_path = '/aws/service/global-infrastructure/regions/{region}/services/{service}/endpoint'.format(region=REGION, service=service)
        endpoint_ssmpaths.append(endpoint_path)
    return endpoint_ssmpaths

def generate_endpoints(endpoint_paths, client):
    endpoints = []
    for endpoint_path in endpoint_paths:
        response = client.get_parameters(
            Names=[
                endpoint_path,
            ]
        )
        endpoint = response['Parameters'][0]['Value']
        endpoints.append(endpoint)
    return endpoints

def main():
    client = boto3.client('ssm')
    paginator = client.get_paginator('get_parameters_by_path')
    response_iterator = paginator.paginate(
        Path='/aws/service/global-infrastructure/regions/{}/services'.format(REGION),
        PaginationConfig={
            'MaxItems': 1000, # サービス数(エンドポイント数)が 1000 を超えたらここを増やしましょう。すぐに超えちゃうかもしれませんね。
        }
    )

    services = generate_services(response_iterator)
    endpoint_ssmpaths = generate_endpoint_ssmpaths(services)
    endpoints = generate_endpoints(endpoint_ssmpaths, client)
    
    with open(CSV_FILENAME, 'w') as f:
        writer = csv.writer(f)
        for i in zip(services, endpoints):
            writer.writerow(i)    

if __name__ == "__main__":
    main()

で、何の役に立つの?

え……?

(もし何かの役に立った場合には教えていただけると幸せになります。)

終わりに

このブログがほんの少しでも世界を良くできれば嬉しいです。
コンサルティング部の西野 (@xiyegen) がお送りしました。