Create an alias for Route53 to CloudFront with the AWS API

Hello sekitaka.

If AWS also works on the developer console, it will not leave a history, so it would be nice to be able to code and manage the source.

DNS settings for CloudFront can be set by executing the API as follows.

# coding:utf-8
#!/usr/bin/python
import boto3

client = boto3.client('route53')
response = client.change_resource_record_sets(
    HostedZoneId='XXXXXXXXXXXX', #Route53 record Domain you want to set(example.com)Zone ID
    ChangeBatch={
        'Comment': u'Any comment',
        'Changes': [
            {
                'Action': 'UPSERT',
                'ResourceRecordSet': {
                    'Name': "xxxxxx.example.com" + ".", #Domain you want to publish
                    'Type': 'A', #When directing to CloudFront, it was written in the document that it should be an A record
                    'AliasTarget': {
                        'HostedZoneId': 'Z2FDTNDATAQYW2', #When pointing to CloudFront, the document said that you should specify this value
                        'DNSName': "xxxxxxxx..cloudfront.net" + ".", #CloudFront distribution domain
                        'EvaluateTargetHealth': False
                    }
                }
            },
        ]
    }
)
print response

The point is that the various settings of ResourceRecordSet have some values that can be used and some that cannot be used, depending on which record type is used and the type of alias. When I set TTL this time, I got addicted to the output of an incomprehensible error.

Fortunately, the boto3 documentation was pretty polite, so I read it carefully and noticed the mistake. ..

Recommended Posts

Create an alias for Route53 to CloudFront with the AWS API
Create an API with Django
[AWS] Create API with API Gateway + Lambda
[For Python] Quickly create an upload file to AWS Lambda Layer
Create a REST API to operate dynamodb with the Django REST Framework
How to create a serverless machine learning API with AWS Lambda
Create an application using the Spotify API
[Python] Quickly create an API with Flask
Try sending an email with the Gmail API Client Library for Java
Get an access token for the Pocket API
Create an AWS GPU instance to train StyleNet
Create an API server quickly with Python + Falcon
Create an API to convert PDF files to TIF images with FastAPI and Docker
Let's create it by applying Protocol Buffer to the API with Serverless Framework.
Create an app that works well with people's reports using the COTOHA API
I tried to create an environment to check regularly using Selenium with AWS Fargate
To automatically send an email with an attachment using the Gmail API in Python
Create a filter to get an Access Token in the Graph API (Flask)
Create a clean DB for testing with FastAPI and unittest the API with pytest
I want to create an API that returns a model with a recursive relationship in the Django REST Framework
How to create an article from the command line
How to create a submenu with the [Blender] plugin
[Boto3] Search for Cognito users with the List Users API
An easy way to create an import module with jupyter
Create a tweet heatmap with the Google Maps API
Create a Layer for AWS Lambda Python with Docker
Create an environment for test automation with AirtestIDE (Tips)
Create an audio file with the text-to-speech function with Google Text To Speak and check the text as a guide for the speech for 3 minutes.
A script that makes it easy to create rich menus with the LINE Messaging API
An introduction to Web API development for those who have completed the Progate Go course
Create a 2D array by adding a row to the end of an empty array with numpy
The first API to make with python Djnago REST framework
Probably the easiest way to create a pdf with Python3
Create an environment for "Deep Learning from scratch" with Docker
Minimum Makefile and buildout.cfg to create an environment with buildout
Create an example game-like stage with just the Blender 2.80 script
How to manipulate the DOM in an iframe with Selenium
Throw appointments to others with the LINE WORKS calendar API
Create a Twitter BOT with the GoogleAppEngine SDK for Python
I'm trying to create an authentication / authorization process with Django
An introduction to the modern socket API to learn in C
Create API with Python, lambda, API Gateway quickly using AWS SAM
[Python Kivy] How to create an exe file with pyinstaller
Create a social integration API for smartphone apps with Django
I want to create a Dockerfile for the time being.
I tried to create an article in Wiki.js with SQLAlchemy
Create an environment with virtualenv
Call the API with python3.
Create a model to store information from the Google Books API for intuitive handling and testing
I tried to create serverless batch processing for the first time with DynamoDB and Step Functions
An easy way to hit the Amazon Product API in Python
[September 2020 version] Explains the procedure to use Gmail API with Python
Send images taken with ESP32-WROOM-32 to AWS (API Gateway → Lambda → S3)
Try to create an execution path diff viewer with angr + bingraphvis
Create a color picker for the color wheel with Python + Qt (PySide)
Switch the package to be installed for each environment with poetry
Grant an access token with the curl command and POST the API
Create REST API that returns the current time with Python3 + Falcon
How to create a heatmap with an arbitrary domain in Python
How to create a label (mask) for segmentation with labelme (semantic segmentation mask)
[Python] Explains how to use the format function with an example