gpt4 book ai didi

amazon-web-services - Grails Amazon Web Services插件route53使用Route53时出错Error ChangeResourceRecordSets

转载 作者:行者123 更新时间:2023-12-02 14:48:23 25 4
gpt4 key购买 nike

我正在尝试使用grails和aws服务插件为route53创建一个新的route53记录集。

我目前正在使用Grails 2.4.5,并且将AmazonWebService插件用于grails 2.4.5

我正在尝试使用此插件在route53上创建一个新的route53记录集。

在BuildConfig.groovy上,我从aws Web服务使用了此插件。
compile ":aws-sdk:1.10.44"
关于route53更改资源记录集,我需要您的帮助。

这是我的代码。

import com.amazonaws.services.route53.AmazonRoute53Client
import com.amazonaws.services.route53.model.AliasTarget
import com.amazonaws.services.route53.model.Change
import com.amazonaws.services.route53.model.ChangeAction
import com.amazonaws.services.route53.model.ChangeBatch
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult
import com.amazonaws.services.route53.model.RRType
import com.amazonaws.services.route53.model.ResourceRecord
import com.amazonaws.services.route53.model.ResourceRecordSet
import grails.plugin.awssdk.AmazonWebService
import grails.transaction.Transactional

@Transactional
class AwsRoute53Service {

AmazonWebService amazonWebService

ChangeResourceRecordSetsResult changeRecordSet() {
AmazonRoute53Client route53Client = amazonWebService.route53

AliasTarget target = new AliasTarget('hostedZoneIDHere', 'app.sample.com.')

target.setEvaluateTargetHealth(true)

List<ResourceRecord> resourceRecords = new ArrayList<>()

resourceRecords.add(new ResourceRecord('dNSNameHere'))

ResourceRecordSet recordSet = new ResourceRecordSet('app.sample.com.', RRType.A)

recordSet.setAliasTarget(target)
recordSet.setResourceRecords(resourceRecords)
recordSet.setTrafficPolicyInstanceId('simple')

List<Change> changes = new ArrayList<>()

changes.add(new Change(ChangeAction.CREATE, recordSet))

ChangeBatch changeBatch = new ChangeBatch(changes)

ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest('hostedZoneIDHere', changeBatch)

return route53Client.changeResourceRecordSets(request)
}
}

当我尝试更改route53资源记录集时出现以下错误。
Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found more than one in Change with [Action=CREATE, Name=app.sample.com., Type=A, SetIdentifier=null] (Service: AmazonRoute53; Status Code: 400; Error Code: InvalidInput; Request ID: 2ca80154-78a7-11e9-b5e7-f7bc7c79e5e6). Stacktrace follows:
Message: Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found more than one in Change with [Action=CREATE, Name=app.sample.com., Type=A, SetIdentifier=null] (Service: AmazonRoute53; Status Code: 400; Error Code: InvalidInput; Request ID: 2ca80154-78a7-11e9-b5e7-f7bc7c79e5e6)

您能告诉我设置有什么问题吗?

如果您现在能解决我的问题,我将感到很高兴。
我真的需要你们的帮助。

最佳答案

以下是我的问题的确切答案

import com.amazonaws.services.route53.AmazonRoute53Client
import com.amazonaws.services.route53.model.AliasTarget
import com.amazonaws.services.route53.model.Change
import com.amazonaws.services.route53.model.ChangeAction
import com.amazonaws.services.route53.model.ChangeBatch
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult
import com.amazonaws.services.route53.model.RRType
import com.amazonaws.services.route53.model.ResourceRecord
import com.amazonaws.services.route53.model.ResourceRecordSet
import grails.plugin.awssdk.AmazonWebService
import grails.transaction.Transactional

@Transactional
class AwsRoute53Service {

private static final String DOMAIN_NAME_SERVER = "${System.env.DOMAIN_NAME_SERVER}"
private static final String HOSTED_ZONE_ID = "${System.env.HOSTED_ZONE_ID}"

AmazonWebService amazonWebService

ChangeResourceRecordSetsResult changeRecordSet() {
AmazonRoute53Client route53Client = amazonWebService.route53

GetHostedZoneResult hostedZoneResult = route53Client.getHostedZone(new GetHostedZoneRequest(HOSTED_ZONE_ID))
HostedZone hostedZone = hostedZoneResult.getHostedZone()

ResourceRecordSet resourceRecordSet = new ResourceRecordSet()
.withName('dNSName')
.withType(RRType.CNAME)
.withTTL(60)
.withResourceRecords([
new ResourceRecord().withValue(DOMAIN_NAME_SERVER)
])

ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest()
.withHostedZoneId(hostedZone.id)
.withChangeBatch(
new ChangeBatch()
.withChanges([
new Change()
.withAction(ChangeAction.CREATE)
.withResourceRecordSet(resourceRecordSet)
])
)

return route53Client.changeResourceRecordSets(request)
}
}

关于amazon-web-services - Grails Amazon Web Services插件route53使用Route53时出错Error ChangeResourceRecordSets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56191340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com