简体   繁体   English

创建指向 S3 的 A 记录

[英]Creating an A record to point to S3

I have an S3 bucket named foo.example.com which is configured for static website hosting, with the endpoint http://foo.example.com.s3-website-us-east-1.amazonaws.com .我有一个名为foo.example.com的 S3 存储桶,它配置为 static 网站托管,端点http://foo.example.com.s3-website-us-east-1.amazonaws.com I'm trying to create an A record in a hosted zone of the same name to point to this S3 bucket.我正在尝试在同名的托管区域中创建一条 A 记录以指向此 S3 存储桶。

    package main 
    
    import (
        "log"
        "strconv"
    
        "github.com/aws/aws-sdk-go/aws"
        "github.com/aws/aws-sdk-go/aws/session"
        "github.com/aws/aws-sdk-go/service/route53"
    )
    
    func main () {
        sess, _ := session.NewSession(&aws.Config{
            Region: aws.String("us-east-1"),
        })
    
        // Create a Route53 service client
        route53Svc := route53.New(sess)
    
        // Set the name of the hosted zone
        hostedZoneName := "foo.example.com"
    
        // Set the maximum number of hosted zones to return
        maxItems := int64(10)
    
        // Call the ListHostedZonesByName action
        result, err := route53Svc.ListHostedZonesByName(&route53.ListHostedZonesByNameInput{
            DNSName:  aws.String(hostedZoneName + "."),
            MaxItems: aws.String(strconv.FormatInt(maxItems, 10)),
        })
        if err != nil {
            log.Fatalf("Error listing hosted zones: %s", err)
        }
    
        // Iterate through the list of hosted zones
        for _, hz := range result.HostedZones {
    
            // Check if the hosted zone name matches the specified name
            if *hz.Name == hostedZoneName + "." {
    
                // Get the hosted zone ID
                hostedZoneID := aws.StringValue(hz.Id)
    
                val := "http://s3-website-us-east-1.amazonaws.com"
    
                // Create an A record for the bucket in the desired hosted zone
                _, err = route53Svc.ChangeResourceRecordSets(&route53.ChangeResourceRecordSetsInput{
                    HostedZoneId: aws.String(hostedZoneID),
                    ChangeBatch: &route53.ChangeBatch{
                        Changes: []*route53.Change{
                            {
                                Action: aws.String("CREATE"),
                                ResourceRecordSet: &route53.ResourceRecordSet{
                                    Type: aws.String("A"),
                                    Name: aws.String(hostedZoneName),
                                    ResourceRecords: []*route53.ResourceRecord{
                                        {
                                            Value: aws.String(val),
                                        },
                                    },
                                    TTL: aws.Int64(300),
                                },
                            },
                        },
                    },
                })
                if err != nil {
                    log.Fatalf("%s",err)
                }
                break
            } 
        }
    }

However I get the following error:但是我收到以下错误:

> InvalidChangeBatch: [Invalid Resource Record: 'FATAL problem:
> ARRDATAIllegalIPv4Address (Value is not a valid IPv4 address)
> encountered with 'http://s3-website-us-east-1.amazonaws.com'']

How do I properly reference the S3 endpoint in the hosted zone?如何正确引用托管区域中的 S3 端点?

You want to create an Alias Record , which allows you to target a DNS name.您想要创建一个Alias Record ,它允许您将 DNS 名称作为目标。 Plain-old A records only accept IPv4 addresses.普通的旧A记录只接受 IPv4 地址。

Action: aws.String("CREATE"),
ResourceRecordSet: &route53.ResourceRecordSet{
    AliasTarget: &route53.AliasTarget{
        DNSName:              aws.String("foo.example.com.s3-website-us-east-1.amazonaws.com"),
        EvaluateTargetHealth: aws.Bool(true),
        HostedZoneId:         aws.String("Z3AADJGX6KTTL2"),
    },
    Name:          aws.String("foo.example.com"),
    Type:          aws.String("A"),
    ...

See the examples in the V1 Go SDK repo.请参阅 V1 Go SDK 存储库中的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 CloudFlare 上创建子域记录时遇到问题,该记录最终将指向我的 AWS S3 存储桶的 static url - Having trouble creating a subdomain record on CloudFlare that will eventually point to my AWS S3 bucket’s static url 将 QuickSight 指向其中包含多个子目录的 s3 Bucket - Point QuickSight to s3 Bucket with sevral subdirectories in it 创建跨区域 S3 VPC 端点 - creating cross region S3 VPC endpoint 如何将域指向 Aws S3 static 网站 - How to point a domain to Aws S3 static website 如何将 GoDaddy 域指向托管在 S3 上的 static 网站? - How to point GoDaddy domain to static website hosted on S3? AWS - 为 s3 static 网站创建记录集 - AWS - Create a record set for an s3 static website 使用 Lambda 中的 Python 创建一个新文件,写入并上传到 S3 - Creating a new file, writing to it and uploading to S3 using Python in Lambda 在 Hive 上创建视图时排除某些 S3 文件夹 - Exclude certain S3 folders while creating a view on Hive 创建 AWS lambda function 以在 s3 存储桶中拆分 pdf 个文件 - Creating an AWS lambda function to split pdf files in a s3 bucket 是否可以使用 pyarrow 从 S3 访问点读取镶木地板文件 - Is it possible to read parquet files from S3 access point using pyarrow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM