feat(rds): EnableHttpEndpoint, DisableHttpEndpoint and HttpEndpointEnabled (#5736)

* feat(rds): EnableHttpEndpoint, DisableHttpEndpoint and HttpEndpointEnabled

EnableHttpEndpoint and DisableHttpEndpoint answered UnsupportedOperation
and DBCluster carried no HttpEndpointEnabled, so Terraform's
enable_http_endpoint and CDK's enableDataApi never read back what they
set.

Clusters now record the flag and report it. The two actions take the
cluster's ARN and raise ResourceNotFoundFault and
InvalidResourceStateFault as the model lists them; CreateDBCluster,
ModifyDBCluster and the AWS::RDS::DBCluster EnableHttpEndpoint property
set it too. Turning it on is refused for engines other than Aurora
PostgreSQL and Aurora MySQL. The Data API itself does not check the
flag, so existing callers keep working.

Closes #5732

* refactor(rds): one cluster ARN parser, and stricter Data API inputs

clusterForResourceArn repeated the ARN parsing, cluster: prefix and
account and Region check of clusterIdentifierFromArnOrName; both now
call clusterIdFromArn, each raising the error its API documents.

The Data API engine check takes aurora-postgresql, aurora-mysql and the
older aurora name exactly instead of any name starting with aurora, and
the AWS::RDS::DBCluster EnableHttpEndpoint property accepts true or
false only, so a malformed value fails instead of turning the endpoint
off.

* fix(rds): take only aurora-mysql and aurora-postgresql for the Data API

The API reference lists those two engines, and new clusters cannot carry
the bare aurora name, so the check no longer accepts it.
This commit is contained in:
David authored and GitHub committed 2026-10-15 16:49:23 -04:00
1 parent a37c27516a
commit 9cd9002e73
13 files changed
+429 -6

No files matched your search

@@ -566,6 +566,7 @@ public class AwsQueryController {
"AddTagsToResource", "ListTagsForResource", "RemoveTagsFromResource",
"CreateDBCluster", "DescribeDBClusters", "DeleteDBCluster", "ModifyDBCluster",
"AddRoleToDBCluster", "RemoveRoleFromDBCluster", "AddRoleToDBInstance", "RemoveRoleFromDBInstance",
"EnableHttpEndpoint", "DisableHttpEndpoint",
"DescribeGlobalClusters",
"CreateDBParameterGroup", "DescribeDBParameterGroups",
"DeleteDBParameterGroup", "ModifyDBParameterGroup", "DescribeDBParameters",
@@ -442,6 +442,11 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
if (!roles.isEmpty()) {
rdsService.validateClusterRoleAssociations(id, resolveOptional(props, "Engine", engine), roles);
}
boolean httpEndpoint = parseStrictBoolProp(props, "EnableHttpEndpoint", engine);
if (httpEndpoint) {
// Refused before a new cluster exists, rather than leaving one behind.
RdsService.requireDataApiEngine(resolveOptional(props, "Engine", engine));
}
boolean created = cluster == null;
if (cluster != null) {
cluster = rdsService.modifyDbCluster(
@@ -470,6 +475,10 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
false, null, engineMode, storageEncrypted);
}
cluster = reconcileClusterRoles(r, cluster, roles, created, ctx.isUpdate(), region);
// EnableHttpEndpoint updates with no interruption; a template that leaves it out wants it off.
if (httpEndpoint != cluster.isHttpEndpointEnabled()) {
cluster = rdsService.setHttpEndpoint(region, cluster.getDbClusterIdentifier(), httpEndpoint);
}
r.setPhysicalId(cluster.getDbClusterIdentifier());
r.getAttributes().put("DBClusterIdentifier", cluster.getDbClusterIdentifier());
if (cluster.getEndpoint() != null) {
@@ -1063,6 +1072,29 @@ public class RdsCfnProvisioner implements CfnResourceProvisioner {
}
}
/**
* A Boolean property read strictly: absent, or resolving to {@code AWS::NoValue}, is false; true
* and false (in any case, as JSON booleans or strings) are themselves; anything else is a
* {@code ValidationError} rather than a silent false.
*/
private boolean parseStrictBoolProp(JsonNode props, String name, CloudFormationTemplateEngine engine) {
if (props == null || !props.has(name)) {
return false;
}
JsonNode value = engine.resolveNodeOmittingNoValue(props.get(name));
if (value == null || value.isMissingNode() || value.isNull()) {
return false;
}
if (value.isBoolean()) {
return value.booleanValue();
}
String text = value.asText();
if ("true".equalsIgnoreCase(text) || "false".equalsIgnoreCase(text)) {
return Boolean.parseBoolean(text);
}
throw new AwsException("ValidationError", name + " must be true or false, not " + text + ".", 400);
}
private boolean parseBoolProp(JsonNode props, String name, CloudFormationTemplateEngine engine) {
return Boolean.parseBoolean(resolveOptional(props, name, engine));
}
@@ -113,6 +113,8 @@ public class RdsQueryHandler {
case "DescribeDBClusterEndpoints" -> handleDescribeDbClusterEndpoints(params, region);
case "ModifyDBClusterEndpoint" -> handleModifyDbClusterEndpoint(params, region);
case "DeleteDBClusterEndpoint" -> handleDeleteDbClusterEndpoint(params, region);
case "EnableHttpEndpoint" -> handleSetHttpEndpoint("EnableHttpEndpoint", params, region, true);
case "DisableHttpEndpoint" -> handleSetHttpEndpoint("DisableHttpEndpoint", params, region, false);
case "AddRoleToDBCluster" -> handleAddRoleToDbCluster(params, region);
case "RemoveRoleFromDBCluster" -> handleRemoveRoleFromDbCluster(params, region);
case "AddRoleToDBInstance" -> handleAddRoleToDbInstance(params, region);
@@ -368,6 +370,16 @@ public class RdsQueryHandler {
new XmlBuilder().raw(eventSubscriptionXml(subscription)).build())).build();
}
private Response handleSetHttpEndpoint(String action, MultivaluedMap<String, String> params, String region,
boolean enabled) {
DbCluster cluster = service.setHttpEndpointByArn(region, params.getFirst("ResourceArn"), enabled);
String result = new XmlBuilder()
.elem("ResourceArn", cluster.getDbClusterArn())
.elem("HttpEndpointEnabled", cluster.isHttpEndpointEnabled())
.build();
return Response.ok(AwsQueryResponse.envelope(action, AwsNamespaces.RDS, result)).build();
}
private Response handleAddRoleToDbCluster(MultivaluedMap<String, String> params, String region) {
service.addRoleToDbCluster(region, params.getFirst("DBClusterIdentifier"),
params.getFirst("RoleArn"), params.getFirst("FeatureName"));
@@ -1180,6 +1192,12 @@ public class RdsQueryHandler {
try {
List<DbRoleAssociation> associatedRoles = parseAssociatedRoles(params);
service.validateClusterRoleAssociations(id, engine, associatedRoles);
boolean enableHttpEndpoint = Boolean.TRUE.equals(parseOptionalBoolean(params, "EnableHttpEndpoint"));
String globalCluster = params.getFirst("GlobalClusterIdentifier");
if (enableHttpEndpoint && (globalCluster == null || globalCluster.isBlank())) {
// A global cluster's members take its Aurora engine; any other create names its own.
RdsService.requireDataApiEngine(engine);
}
Double serverlessV2Min = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MinCapacity");
Double serverlessV2Max = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MaxCapacity");
Integer serverlessV2SecondsUntilAutoPause = parseIntegerParam(
@@ -1222,6 +1240,9 @@ public class RdsQueryHandler {
throw e;
}
}
if (enableHttpEndpoint) {
cluster = service.setHttpEndpoint(region, id, true);
}
String result = dbClusterXml(cluster);
return Response.ok(AwsQueryResponse.envelope("CreateDBCluster", AwsNamespaces.RDS, result)).build();
} catch (AwsException e) {
@@ -1331,9 +1352,16 @@ public class RdsQueryHandler {
Double serverlessV2Max = parseDoubleParam(params, "ServerlessV2ScalingConfiguration.MaxCapacity");
Integer serverlessV2SecondsUntilAutoPause = parseIntegerParam(
params, "ServerlessV2ScalingConfiguration.SecondsUntilAutoPause");
Boolean enableHttpEndpoint = parseOptionalBoolean(params, "EnableHttpEndpoint");
if (Boolean.TRUE.equals(enableHttpEndpoint)) {
RdsService.requireDataApiEngine(service.getDbCluster(id, region).getEngineIdentifier());
}
DbCluster cluster = service.modifyDbCluster(id, newPassword, iamEnabled,
serverlessV2Min, serverlessV2Max, serverlessV2SecondsUntilAutoPause,
manageMasterUserPassword, masterUserSecretKmsKeyId, region);
if (enableHttpEndpoint != null) {
cluster = service.setHttpEndpoint(region, id, enableHttpEndpoint);
}
String result = dbClusterXml(cluster);
return Response.ok(AwsQueryResponse.envelope("ModifyDBCluster", AwsNamespaces.RDS, result)).build();
} catch (AwsException e) {
@@ -2918,6 +2946,7 @@ public class RdsQueryHandler {
.elem("LatestRestorableTime", Instant.now().toString());
}
xml.elem("IAMDatabaseAuthenticationEnabled", c.isIamDatabaseAuthenticationEnabled())
.elem("HttpEndpointEnabled", c.isHttpEndpointEnabled())
.elem("MultiAZ", c.isMultiAz())
.elem("StorageEncrypted", c.isStorageEncrypted())
.elem("AvailabilityZone", c.getAvailabilityZone() != null ? c.getAvailabilityZone() : config.defaultAvailabilityZone())
@@ -2213,18 +2213,30 @@ public class RdsService implements Resettable, ResourceProvider {
if (!source.startsWith("arn:")) {
return source;
}
return clusterIdFromArn(source, region,
() -> new AwsException("InvalidParameterValue", "Invalid DB cluster identifier: " + source, 400),
() -> new AwsException("DBClusterNotFoundFault", "DB cluster " + source + " not found.", 404));
}
/**
* The cluster identifier an RDS cluster ARN names. An ARN that does not parse or is not an RDS
* cluster ARN raises {@code malformed}; one for another account or Region names no cluster here
* and raises {@code elsewhere}. Each caller supplies the errors its API documents.
*/
private String clusterIdFromArn(String source, String region, Supplier<AwsException> malformed,
Supplier<AwsException> elsewhere) {
AwsArnUtils.Arn arn;
try {
arn = AwsArnUtils.parse(source);
} catch (IllegalArgumentException malformed) {
throw new AwsException("InvalidParameterValue", "Invalid DB cluster identifier: " + source, 400);
} catch (IllegalArgumentException e) {
throw malformed.get();
}
String resource = arn.resource();
if (!"rds".equals(arn.service()) || !resource.startsWith("cluster:")) {
throw new AwsException("InvalidParameterValue", "Invalid DB cluster identifier: " + source, 400);
throw malformed.get();
}
if (!region.equals(arn.region()) || !currentAccountId().equals(arn.accountId())) {
throw new AwsException("DBClusterNotFoundFault", "DB cluster " + source + " not found.", 404);
throw elsewhere.get();
}
return resource.substring("cluster:".length());
}
@@ -9753,6 +9765,67 @@ public class RdsService implements Resettable, ResourceProvider {
return subscription;
}
// ── Data API endpoint ─────────────────────────────────────────────────────
/**
* Turns a cluster's Data API endpoint on or off by the cluster's ARN, as EnableHttpEndpoint and
* DisableHttpEndpoint do. An ARN that names no cluster here is {@code ResourceNotFoundFault}, a
* cluster that is not available {@code InvalidResourceStateFault}. The flag is recorded and
* reported; the Data API does not consult it.
*/
public synchronized DbCluster setHttpEndpointByArn(String region, String resourceArn, boolean enabled) {
requireParameter(resourceArn, "ResourceArn");
String effectiveRegion = effectiveRegion(region);
DbCluster cluster = clusterForResourceArn(resourceArn, effectiveRegion);
if (cluster.getStatus() != null && cluster.getStatus() != DbInstanceStatus.AVAILABLE) {
throw new AwsException("InvalidResourceStateFault",
"DB cluster " + cluster.getDbClusterIdentifier() + " is not in available state.", 400);
}
return setHttpEndpoint(effectiveRegion, cluster, enabled);
}
/** Sets the flag on a cluster named by identifier, for CreateDBCluster, ModifyDBCluster and CloudFormation. */
public synchronized DbCluster setHttpEndpoint(String region, String clusterId, boolean enabled) {
String effectiveRegion = effectiveRegion(region);
return setHttpEndpoint(effectiveRegion, getDbCluster(clusterId, effectiveRegion), enabled);
}
private DbCluster setHttpEndpoint(String effectiveRegion, DbCluster cluster, boolean enabled) {
if (enabled) {
requireDataApiEngine(engineName(cluster));
}
cluster.setHttpEndpointEnabled(enabled);
putClusterForScope(currentAccountId(), effectiveRegion, cluster.getDbClusterIdentifier(), cluster);
LOG.infov("Data API endpoint {0} for DB cluster {1}", enabled ? "enabled" : "disabled",
cluster.getDbClusterIdentifier());
return RESPONSE_COPIER.convertValue(cluster, DbCluster.class);
}
private static final Set<String> DATA_API_ENGINES = Set.of("aurora-postgresql", "aurora-mysql");
/**
* The Data API is offered for Aurora PostgreSQL and Aurora MySQL only, so turning it on for any
* other engine is refused; a create checks this before the cluster exists.
*/
public static void requireDataApiEngine(String engine) {
String name = engine == null ? "postgres" : engine.toLowerCase(Locale.ROOT);
if (!DATA_API_ENGINES.contains(name)) {
throw new AwsException("InvalidParameterCombination", "The Data API (HTTP endpoint) is available for "
+ "Aurora PostgreSQL and Aurora MySQL DB clusters only, not for engine " + name + ".", 400);
}
}
private DbCluster clusterForResourceArn(String resourceArn, String region) {
Supplier<AwsException> notFound = () -> new AwsException("ResourceNotFoundFault",
"The specified resource ARN " + resourceArn + " doesn't refer to an existing DB cluster.", 404);
DbCluster cluster = findClusterForScope(currentAccountId(), region,
clusterIdFromArn(resourceArn, region, notFound, notFound));
if (cluster == null || !resourceArn.equals(cluster.getDbClusterArn())) {
throw notFound.get();
}
return cluster;
}
// ── IAM role associations ─────────────────────────────────────────────────
/**
@@ -22,6 +22,7 @@ public class DbCluster {
private DbEndpoint endpoint;
private DbEndpoint readerEndpoint;
private boolean iamDatabaseAuthenticationEnabled;
private boolean httpEndpointEnabled;
private List<String> dbClusterMembers = new ArrayList<>();
// The member that holds the writer role. Null on a cluster persisted before the role was
// modelled, in which case the first member is the writer, as it always was reported.
@@ -118,6 +119,10 @@ public class DbCluster {
this.iamDatabaseAuthenticationEnabled = iamDatabaseAuthenticationEnabled;
}
/** Whether the Data API endpoint is on; EnableHttpEndpoint and DisableHttpEndpoint set it. */
public boolean isHttpEndpointEnabled() { return httpEndpointEnabled; }
public void setHttpEndpointEnabled(boolean httpEndpointEnabled) { this.httpEndpointEnabled = httpEndpointEnabled; }
public List<String> getDbClusterMembers() { return dbClusterMembers; }
public void setDbClusterMembers(List<String> dbClusterMembers) { this.dbClusterMembers = dbClusterMembers; }