fix(appsync): use ApiKey.id as the API key value (#2645)

CreateApiKey returned a short random id and kept the value the execute
endpoint validates in a non-model apiKey field, which the AWS CLI and SDKs
drop. On AWS the id itself is the da2- key value sent as x-api-key, so make
id that value, validate against it, and drop the extra field. Keys persisted
by earlier builds keep their short id, stay listable and deletable, and never
authenticate (as before).
This commit is contained in:
武田隆志 authored and GitHub committed 2026-08-28 09:59:42 -04:00
1 parent 3b0e31b888
commit 29325006bb
9 files changed
+70 -42

No files matched your search

@@ -133,9 +133,9 @@ class AppSyncTest {
keyId = resp.apiKey().id();
assertThat(keyId).isNotBlank();
assertThat(resp.apiKey().description()).isEqualTo("sdk-test-key");
// AWS SDK v2 ApiKey has no apiKey() accessor; Floci returns the da2- secret on the wire.
apiKeyValue = fetchApiKeyValue(apiId, keyId);
assertThat(apiKeyValue).startsWith("da2-");
// As on AWS, the id is the key value sent as x-api-key.
assertThat(keyId).matches("da2-[a-z0-9]{26}");
apiKeyValue = keyId;
}
@Test
@@ -1315,24 +1315,4 @@ class AppSyncTest {
assertThat(location.get("column")).isNotNull();
assertThat(location.get("span")).isEqualTo(-1);
}
@SuppressWarnings("unchecked")
private static String fetchApiKeyValue(String apiId, String keyId) throws Exception {
String url = TestFixtures.endpoint() + "/v1/apis/" + apiId + "/apikeys";
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/appsync/aws4_request")
.GET()
.build();
HttpResponse<String> resp = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
Map<String, Object> body = mapper.readValue(resp.body(), Map.class);
List<Map<String, Object>> keys = (List<Map<String, Object>>) body.get("apiKeys");
assertThat(keys).isNotEmpty();
for (Map<String, Object> key : keys) {
if (keyId.equals(key.get("id"))) {
return String.valueOf(key.get("apiKey"));
}
}
throw new IllegalStateException("API key not listed for id " + keyId);
}
}