diff --git a/docs/services/cloudformation.md b/docs/services/cloudformation.md index e04e77c4f5..8a8f10eac0 100644 --- a/docs/services/cloudformation.md +++ b/docs/services/cloudformation.md @@ -175,7 +175,7 @@ cross-resource references. | SNS | `Topic`, `Subscription`, `TopicPolicy` | | SES | `EmailIdentity` (BYODKIM is not supported by this resource; Easy DKIM DNS attributes use the shared emulator signing zone `dkim.amazonses.com` rather than AWS's region- and identity-specific zone assignment) | | DynamoDB | `Table` (`TimeToLiveSpecification` applied on create and update; to rename an enabled TTL attribute, disable TTL in one update and enable the new attribute in a later one), `GlobalTable` | -| Lambda | `Function` (Zip via S3/inline `ZipFile`, Image, and the `hot-reload` bind-mount bucket), `LayerVersion`, `EventSourceMapping` (SQS, Kinesis, DynamoDB Streams; `ParallelizationFactor` and `TumblingWindowInSeconds` are ignored), `Version`, `Alias` (also what SAM's `AutoPublishAlias` expands into), `Permission`, `EventInvokeConfig` (also what a SAM function's `EventInvokeConfig` expands into), `MicrovmImage`, `NetworkConnector`, `Url`, `WebFunction` (control plane only; the endpoint domain does not serve requests yet), `WebFunctionEndpoint` (`RegionalEndpoints` is not exposed to `Fn::GetAtt` yet), `WebFunctionRevision` (every property is createOnly, so a change mints a new revision). Inline `ZipFile` packages include the `cfn-response` (Node.js) / `cfnresponse` (Python) module AWS injects for that code path, so Solutions-style custom-resource handlers work. | +| Lambda | `Function` (Zip via S3/inline `ZipFile`, Image, and the `hot-reload` bind-mount bucket), `LayerVersion`, `EventSourceMapping` (SQS, Kinesis, DynamoDB Streams; `ParallelizationFactor` and `TumblingWindowInSeconds` are ignored), `Version`, `Alias` (also what SAM's `AutoPublishAlias` expands into), `Permission`, `EventInvokeConfig` (also what a SAM function's `EventInvokeConfig` expands into), `MicrovmImage`, `NetworkConnector`, `Url`, `WebFunction` (control plane only; the endpoint domain does not serve requests yet), `WebFunctionEndpoint`, `WebFunctionRevision` (every property is createOnly, so a change mints a new revision). Inline `ZipFile` packages include the `cfn-response` (Node.js) / `cfnresponse` (Python) module AWS injects for that code path, so Solutions-style custom-resource handlers work. | | IAM | `Role`, `User` (template `LoginProfile` and `PermissionsBoundary` are ignored; an API-created login profile is removed on delete), `AccessKey`, `Policy`, `ManagedPolicy`, `InstanceProfile` | | Organizations | `Organization`, `OrganizationalUnit`, `Account`, `Policy`, `ResourcePolicy` | | SSM | `Parameter` | diff --git a/docs/services/lambda-web-functions.md b/docs/services/lambda-web-functions.md index 9fac7d55df..4d1d5f28c8 100644 --- a/docs/services/lambda-web-functions.md +++ b/docs/services/lambda-web-functions.md @@ -145,6 +145,6 @@ The account quotas are not applied, so `AccountRequestThrottles` and `AccountAct ## CloudFormation -`AWS::Lambda::WebFunction`, `AWS::Lambda::WebFunctionRevision` and `AWS::Lambda::WebFunctionEndpoint` provision through the resource registry. `Ref` of each is its ARN. Every property of a revision is createOnly, so a changed revision mints a new one and the displaced revision is deleted once the update commits. An endpoint keeps its identity while its function, name, type and regions stay the same. A changed type or region list under the same name is refused the way CloudFormation refuses to replace a custom-named resource. `Fn::GetAtt` on `RegionalEndpoints` is not supported yet. +`AWS::Lambda::WebFunction`, `AWS::Lambda::WebFunctionRevision` and `AWS::Lambda::WebFunctionEndpoint` provision through the resource registry. `Ref` of each is its ARN. Every property of a revision is createOnly, so a changed revision mints a new one and the displaced revision is deleted once the update commits. An endpoint keeps its identity while its function, name, type and regions stay the same. A changed type or region list under the same name is refused the way CloudFormation refuses to replace a custom-named resource. `Fn::GetAtt` on `RegionalEndpoints` gives an object keyed by region, with the members of the API's `regionalEndpoints` in PascalCase, as on AWS. It is not a string, so an output or a `Fn::Sub` variable that names it fails the stack, as on AWS. CloudFormation has no `AutoDeploymentMode` property, so an endpoint it creates is always `Disabled` and needs `RevisionWeights`, as on AWS. Name the revision with `Fn::GetAtt` so a replaced revision moves the endpoint with it. A stack update that fails after an in-place change to a function's tags or an endpoint's configuration puts the previous values back. diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnResourceProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnResourceProvisioner.java index bbf74fdd2b..35cd5dfa3e 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnResourceProvisioner.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnResourceProvisioner.java @@ -1,6 +1,8 @@ package io.github.hectorvent.floci.services.cloudformation.provisioners; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.LongNode; import com.fasterxml.jackson.databind.node.TextNode; import io.github.hectorvent.floci.services.cloudformation.model.StackEvent; @@ -29,11 +31,23 @@ public interface CfnResourceProvisioner { return Map.of(); } + /** GetAtt attributes the registry schema types as objects or arrays, stored as JSON text, by resource type. */ + default Map> jsonAttributes() { + return Map.of(); + } + /** The JSON type of a stored GetAtt value; most resource attributes are strings. */ default JsonNode attributeValue(String resourceType, String attributeName, String value) { if (integerAttributes().getOrDefault(resourceType, Set.of()).contains(attributeName)) { return LongNode.valueOf(Long.parseLong(value)); } + if (jsonAttributes().getOrDefault(resourceType, Set.of()).contains(attributeName)) { + try { + return StoredJson.MAPPER.readTree(value); + } catch (JsonProcessingException e) { + throw new IllegalStateException("Invalid stored " + resourceType + " attribute " + attributeName, e); + } + } return TextNode.valueOf(value); } @@ -177,4 +191,12 @@ public interface CfnResourceProvisioner { // no-op by default: only a provisioner with tracking of its own to carry (generated // sub-resources, cleanup entries, an undo snapshot) needs this } + + /** Keeps the mapper private, which an interface field cannot be. */ + final class StoredJson { + private static final ObjectMapper MAPPER = new ObjectMapper(); + + private StoredJson() { + } + } } diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LambdaWebCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LambdaWebCfnProvisioner.java index 092e2fcf52..1f4c54144e 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LambdaWebCfnProvisioner.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LambdaWebCfnProvisioner.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.services.cloudformation.model.StackResource; +import io.github.hectorvent.floci.services.lambdaweb.LambdaWebResponses; import io.github.hectorvent.floci.services.lambdaweb.LambdaWebService; import io.github.hectorvent.floci.services.lambdaweb.model.WebFunction; import io.github.hectorvent.floci.services.lambdaweb.model.WebFunctionEndpoint; @@ -120,7 +121,9 @@ public class LambdaWebCfnProvisioner implements CfnResourceProvisioner { String region = snapshot.path("region").asText(); String functionArn = snapshot.path("functionArn").asText(); if ("endpoint".equals(snapshot.path("type").asText())) { - service.updateEndpoint(region, functionArn, snapshot.path("endpointName").asText(), snapshot.get("patch")); + WebFunctionEndpoint restored = service.updateEndpoint(region, functionArn, + snapshot.path("endpointName").asText(), snapshot.get("patch")).after(); + resource.getAttributes().put("RegionalEndpoints", regionalEndpoints(restored)); } else { service.replaceTags(region, functionArn, MAPPER.convertValue(snapshot.get("tags"), new TypeReference>() {})); @@ -219,6 +222,7 @@ public class LambdaWebCfnProvisioner implements CfnResourceProvisioner { r.getAttributes().put("FunctionArn", endpoint.functionArn); r.getAttributes().put("EndpointArn", endpoint.endpointArn); r.getAttributes().put("DomainName", endpoint.domainName); + r.getAttributes().put("RegionalEndpoints", regionalEndpoints(endpoint)); r.getAttributes().put("State", "Active"); r.getAttributes().put("StateReason", "The endpoint is active and invokable."); if (endpoint.updateStatus != null) { @@ -344,6 +348,32 @@ public class LambdaWebCfnProvisioner implements CfnResourceProvisioner { return out; } + @Override + public Map> jsonAttributes() { + return Map.of(ENDPOINT, Set.of("RegionalEndpoints")); + } + + private static String regionalEndpoints(WebFunctionEndpoint endpoint) { + return upperKeys(MAPPER.valueToTree(LambdaWebResponses.regionalEndpoints(endpoint)), false).toString(); + } + + /** The API's members in PascalCase. The region names that key RegionalEndpoints stay as they are. */ + private static JsonNode upperKeys(JsonNode node, boolean member) { + if (node.isObject()) { + ObjectNode out = MAPPER.createObjectNode(); + node.properties().forEach(entry -> out.set(member + ? Character.toUpperCase(entry.getKey().charAt(0)) + entry.getKey().substring(1) + : entry.getKey(), upperKeys(entry.getValue(), true))); + return out; + } + if (node.isArray()) { + ArrayNode out = MAPPER.createArrayNode(); + node.forEach(item -> out.add(upperKeys(item, true))); + return out; + } + return node; + } + private static JsonNode lowerKeys(JsonNode node) { if (node.isObject()) { return toCamelCase(node, Set.of()); diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftEventSubscriptionCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftEventSubscriptionCfnProvisioner.java index c71f8a3f7c..c31ab8a1e6 100644 --- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftEventSubscriptionCfnProvisioner.java +++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftEventSubscriptionCfnProvisioner.java @@ -71,15 +71,8 @@ public class RedshiftEventSubscriptionCfnProvisioner implements CfnResourceProvi } @Override - public JsonNode attributeValue(String resourceType, String attributeName, String value) { - if ("SourceIdsList".equals(attributeName) || "EventCategoriesList".equals(attributeName)) { - try { - return MAPPER.readTree(value); - } catch (JsonProcessingException e) { - throw new IllegalStateException("Invalid stored Redshift event subscription attribute " + attributeName, e); - } - } - return CfnResourceProvisioner.super.attributeValue(resourceType, attributeName, value); + public Map> jsonAttributes() { + return Map.of(TYPE, Set.of("SourceIdsList", "EventCategoriesList")); } @Override diff --git a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebResponses.java b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebResponses.java index c0d7c024d3..1b33ed6487 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebResponses.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebResponses.java @@ -13,7 +13,7 @@ import java.util.Map; import java.util.TreeMap; /** The wire shapes of Lambda Web responses. AWS emits members in alphabetical order with microsecond timestamps. */ -final class LambdaWebResponses { +public final class LambdaWebResponses { private static final DateTimeFormatter TIMESTAMP = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss.SSSSSS'Z'").withZone(ZoneOffset.UTC); @@ -123,6 +123,17 @@ final class LambdaWebResponses { static Map endpoint(WebFunctionEndpoint endpoint, WebFunctionEndpoint regionalSource, View view) { Map out = endpointSummary(endpoint, view); out.put("functionArn", endpoint.functionArn); + out.put("regionalEndpoints", regionalEndpoints(endpoint, regionalSource, view)); + return out; + } + + /** The per-region block of a stored endpoint, which CloudFormation's RegionalEndpoints gives too. */ + public static Map regionalEndpoints(WebFunctionEndpoint endpoint) { + return regionalEndpoints(endpoint, endpoint, View.STORED); + } + + private static Map regionalEndpoints(WebFunctionEndpoint endpoint, WebFunctionEndpoint regionalSource, + View view) { Map regional = node(); for (String region : endpoint.regions) { Map entry = node(); @@ -136,8 +147,7 @@ final class LambdaWebResponses { putEndpointState(entry, regionalSource, view, true); regional.put(region, entry); } - out.put("regionalEndpoints", regional); - return out; + return regional; } private static void putConfigs(Map out, WebFunctionEndpoint endpoint) { diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaWebIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaWebIntegrationTest.java index edbcbc426d..ebce28eb52 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaWebIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaWebIntegrationTest.java @@ -1,17 +1,21 @@ package io.github.hectorvent.floci.services.cloudformation; +import com.fasterxml.jackson.databind.JsonNode; import io.github.hectorvent.floci.core.common.XmlParser; import io.github.hectorvent.floci.services.iam.IamService; +import io.github.hectorvent.floci.services.lambda.LambdaService; import io.github.hectorvent.floci.services.lambdaweb.LambdaWebCodeBuckets; import io.github.hectorvent.floci.services.lambdaweb.LambdaWebRoles; import io.github.hectorvent.floci.services.lambdaweb.LambdaWebZips; import io.github.hectorvent.floci.services.s3.S3Service; +import io.quarkus.test.InjectMock; import io.quarkus.test.junit.QuarkusTest; import io.restassured.response.ValidatableResponse; import jakarta.inject.Inject; import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; +import java.util.List; import java.util.Map; import static io.restassured.RestAssured.given; @@ -35,6 +39,10 @@ class CloudFormationLambdaWebIntegrationTest { private static final String CFN_AUTH = "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/cloudformation/aws4_request"; private static final String BUCKET = "cfn-web-code"; + private static final String PROBE_TOKEN = "arn:aws:lambda:us-east-1:000000000000:function:cfn-web-regional-probe"; + + @InjectMock + LambdaService lambdaService; @Inject S3Service s3Service; @@ -144,6 +152,60 @@ class CloudFormationLambdaWebIntegrationTest { .then().statusCode(404)); } + @Test + void aCustomResourceIsGivenRegionalEndpointsAsAnObject() { + LambdaWebRoles.trustLambda(iamService, "arn:aws:iam::000000000000:role/cfn-web"); + LambdaWebCodeBuckets.create(s3Service, BUCKET); + s3Service.putObject(BUCKET, "app.zip", LambdaWebZips.indexJs(""), "application/zip", Map.of()); + String suffix = Long.toString(System.nanoTime(), 36); + String functionName = "cfn-web-probe-" + suffix; + String stackName = "cfn-web-probe-stack-" + suffix; + CustomResourceProbe handler = CustomResourceProbe.stub(lambdaService, PROBE_TOKEN, "regional-probe"); + String probe = """ + "Probe": { + "Type": "Custom::Probe", + "Properties": {"ServiceToken": "%s", "Value": {"Fn::GetAtt": ["Ep", "RegionalEndpoints"]}} + }, + """.formatted(PROBE_TOKEN); + + cloudFormation(stackName, "CreateStack", template(functionName, 30, probe)); + await().untilAsserted(() -> describeStacks(stackName, "CREATE_COMPLETE")); + String revisionId = outputs(describeStacks(stackName, "CREATE_COMPLETE")).get("RevId"); + JsonNode value = handler.request("Create").path("ResourceProperties").path("Value"); + assertEquals(List.of("us-east-1"), value.properties().stream().map(Map.Entry::getKey).toList()); + JsonNode home = value.path("us-east-1"); + assertEquals(List.of("AuthType", "RevisionWeights", "State", "StateReason"), + home.properties().stream().map(Map.Entry::getKey).toList()); + assertEquals("ApplicationManaged", home.path("AuthType").asText()); + assertEquals(revisionId, home.path("RevisionWeights").path(0).path("RevisionId").asText()); + // The custom resource stringifies every scalar it is given, so the weight is compared as text. + assertEquals("100", home.path("RevisionWeights").path(0).path("Weight").asText()); + assertEquals("Active", home.path("State").asText()); + assertEquals("The endpoint is active in the region.", home.path("StateReason").asText()); + + cloudFormation(stackName, "DeleteStack", null); + await().untilAsserted(() -> given().when().get("/2025-03-07/web-functions/" + functionName) + .then().statusCode(404)); + } + + @Test + void regionalEndpointsIsAnObjectThatAnOutputCannotHold() { + LambdaWebRoles.trustLambda(iamService, "arn:aws:iam::000000000000:role/cfn-web"); + LambdaWebCodeBuckets.create(s3Service, BUCKET); + s3Service.putObject(BUCKET, "app.zip", LambdaWebZips.indexJs(""), "application/zip", Map.of()); + String suffix = Long.toString(System.nanoTime(), 36); + String functionName = "cfn-web-regional-" + suffix; + String stackName = "cfn-web-regional-stack-" + suffix; + String state = "\"EpState\": {\"Value\": {\"Fn::GetAtt\": [\"Ep\", \"State\"]}}"; + + cloudFormation(stackName, "CreateStack", template(functionName, 30).replace(state, + state + ", \"EpRegional\": {\"Value\": {\"Fn::GetAtt\": [\"Ep\", \"RegionalEndpoints\"]}}")); + await().untilAsserted(() -> describeStacks(stackName, "ROLLBACK_COMPLETE")); + stackEvents(stackName).body(containsString("Template format error: Every Value member must be a string.")); + given().when().get("/2025-03-07/web-functions/" + functionName).then().statusCode(404); + cloudFormation(stackName, "DeleteStack", null); + } + private static ValidatableResponse stackEvents(String stackName) { return given() .contentType("application/x-www-form-urlencoded") diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CustomResourceProbe.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CustomResourceProbe.java new file mode 100644 index 0000000000..860e4dc454 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CustomResourceProbe.java @@ -0,0 +1,63 @@ +package io.github.hectorvent.floci.services.cloudformation; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import io.github.hectorvent.floci.services.lambda.LambdaService; +import io.github.hectorvent.floci.services.lambda.model.InvocationType; +import io.github.hectorvent.floci.services.lambda.model.InvokeResult; + +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import static io.restassured.RestAssured.given; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +/** + * The handler of a custom resource in a stack test. It stands in for the ServiceToken Lambda on a + * mocked {@link LambdaService}, keeps every request it is sent, and answers each the way a handler + * does: a PUT of a SUCCESS result to the event's {@code ResponseURL}. + */ +final class CustomResourceProbe { + + private static final ObjectMapper MAPPER = new ObjectMapper(); + + private final List events = new CopyOnWriteArrayList<>(); + private final String physicalId; + + private CustomResourceProbe(String physicalId) { + this.physicalId = physicalId; + } + + static CustomResourceProbe stub(LambdaService lambdaService, String serviceToken, String physicalId) { + CustomResourceProbe probe = new CustomResourceProbe(physicalId); + when(lambdaService.invoke(any(), eq(serviceToken), any(), eq(InvocationType.RequestResponse))) + .thenAnswer(invocation -> { + JsonNode event = MAPPER.readTree((byte[]) invocation.getArgument(2)); + probe.events.add(event); + probe.succeed(event); + return new InvokeResult(200, null, "null".getBytes(StandardCharsets.UTF_8), null, "req-1"); + }); + return probe; + } + + /** The first request of {@code requestType}, such as Create. */ + JsonNode request(String requestType) { + return events.stream().filter(event -> requestType.equals(event.path("RequestType").asText())) + .findFirst().orElseThrow(() -> new AssertionError("No " + requestType + " request in " + events)); + } + + private void succeed(JsonNode event) { + ObjectNode response = MAPPER.createObjectNode().put("Status", "SUCCESS") + .put("RequestId", event.get("RequestId").asText()) + .put("StackId", event.get("StackId").asText()) + .put("LogicalResourceId", event.get("LogicalResourceId").asText()) + .put("PhysicalResourceId", physicalId); + given().body(response.toString()).when().put(URI.create(event.get("ResponseURL").asText()).getPath()) + .then().statusCode(200); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LambdaWebCfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LambdaWebCfnProvisionerTest.java index 4d4e9b60c5..d22b3c186c 100644 --- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LambdaWebCfnProvisionerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/LambdaWebCfnProvisionerTest.java @@ -44,7 +44,8 @@ class LambdaWebCfnProvisionerTest { private static final Set REVISION_ATTRIBUTES = Set.of("FunctionArn", "RevisionArn", "RevisionId", "State", "StateReason", "CreatedAt"); private static final Set ENDPOINT_ATTRIBUTES = - Set.of("FunctionArn", "EndpointArn", "DomainName", "State", "StateReason", "CreatedAt", "UpdatedAt"); + Set.of("FunctionArn", "EndpointArn", "DomainName", "RegionalEndpoints", "State", "StateReason", "CreatedAt", + "UpdatedAt"); private final LambdaWebService service = mock(LambdaWebService.class); private final LambdaWebCfnProvisioner provisioner = new LambdaWebCfnProvisioner(service); @@ -371,6 +372,34 @@ class LambdaWebCfnProvisionerTest { assertEquals("The endpoint is active and invokable.", r.getAttributes().get("StateReason")); } + @Test + void regionalEndpointsIsTheApiBlockInPascalCase() { + WebFunctionEndpoint created = endpoint("prod", "PerRegion", List.of("us-east-1", "us-west-2")); + created.authType = "ApplicationManaged"; + WebFunctionEndpoint.RevisionWeight weight = new WebFunctionEndpoint.RevisionWeight(); + weight.revisionId = "rev-aaaaa"; + weight.weight = 100; + created.revisionWeights.add(weight); + created.scalingConfig = new WebFunctionEndpoint.ScalingConfig(); + created.scalingConfig.maxEnvironments = 3; + created.regionalDomainNames.put("us-east-1", "abc.001.lambda-web.us-east-1.localhost:4566"); + created.regionalDomainNames.put("us-west-2", "abc.001.lambda-web.us-west-2.localhost:4566"); + when(service.createEndpoint(eq(REGION), eq("app"), any())).thenReturn(created); + StackResource r = resource(LambdaWebCfnProvisioner.ENDPOINT); + + provisioner.provision(r, endpointProps("PerRegion"), ctx(null)); + + String entry = "{\"AuthType\":\"ApplicationManaged\",\"DomainName\":\"abc.001.lambda-web.%s.localhost:4566\"," + + "\"RevisionWeights\":[{\"RevisionId\":\"rev-aaaaa\",\"Weight\":100}]," + + "\"ScalingConfig\":{\"MaxEnvironments\":3},\"State\":\"Active\"," + + "\"StateReason\":\"The endpoint is active in the region.\"}"; + assertEquals("{\"us-east-1\":" + entry.formatted("us-east-1") + ",\"us-west-2\":" + entry.formatted("us-west-2") + + "}", provisioner.attributeValue(LambdaWebCfnProvisioner.ENDPOINT, "RegionalEndpoints", + r.getAttributes().get("RegionalEndpoints")).toString()); + assertEquals("Active", provisioner.attributeValue(LambdaWebCfnProvisioner.ENDPOINT, "State", + r.getAttributes().get("State")).textValue()); + } + @Test void endpointWithTheSameIdentityIsUpdatedInPlace() { WebFunctionEndpoint existing = endpoint("prod", "HomeRegion", List.of("us-east-1")); @@ -405,7 +434,14 @@ class LambdaWebCfnProvisionerTest { assertEquals("The endpoint is updated.", r.getAttributes().get("UpdateStatusReason")); assertFalse(provisioner.hasReplacementUpdate(r)); // A failed stack update puts the prior configuration back. + WebFunctionEndpoint restoredEndpoint = endpoint("prod", "HomeRegion", List.of("us-east-1")); + restoredEndpoint.authType = "ApplicationManaged"; + when(service.updateEndpoint(eq(REGION), eq(FN_ARN), eq("prod"), any())) + .thenReturn(new LambdaWebService.EndpointUpdate(updated, restoredEndpoint)); assertTrue(provisioner.rollbackUpdate(r)); + assertEquals("ApplicationManaged", provisioner.attributeValue(LambdaWebCfnProvisioner.ENDPOINT, + "RegionalEndpoints", r.getAttributes().get("RegionalEndpoints")).path("us-east-1").path("AuthType") + .textValue(), "the restored endpoint's regional block"); ArgumentCaptor restored = ArgumentCaptor.forClass(JsonNode.class); verify(service).updateEndpoint(eq(REGION), eq(FN_ARN), eq("prod"), restored.capture()); assertEquals("ApplicationManaged", restored.getValue().path("authType").asText()); diff --git a/src/test/resources/cloudformation/getatt-attribute-gaps.tsv b/src/test/resources/cloudformation/getatt-attribute-gaps.tsv index 4c6a03ad30..8850e1f6b6 100644 --- a/src/test/resources/cloudformation/getatt-attribute-gaps.tsv +++ b/src/test/resources/cloudformation/getatt-attribute-gaps.tsv @@ -20,7 +20,6 @@ AWS::Lambda::MicrovmImage LatestFailedImageVersion failure history is not tracke AWS::Lambda::MicrovmImage State microvm image state is not modelled AWS::Lambda::MicrovmImage UpdatedAt microvm image lifecycle fields are not tracked AWS::Lambda::NetworkConnector State network connector state is not modelled -AWS::Lambda::WebFunctionEndpoint RegionalEndpoints the attribute is a map of per-region state, and Floci GetAtt values are strings; the endpoint's own State and UpdateStatus carry the same values AWS::Lambda::Permission Id schema gives no description and AWS's value is unclear; the physical id is a composite functionName|statementId AWS::Pipes::Pipe CreationTime pipe lifecycle timestamps are not tracked AWS::Pipes::Pipe CurrentState pipe state transitions are not modelled diff --git a/tools/docs/cfn_resource_types.yaml b/tools/docs/cfn_resource_types.yaml index e8c4e44c19..6214d9a750 100644 --- a/tools/docs/cfn_resource_types.yaml +++ b/tools/docs/cfn_resource_types.yaml @@ -184,7 +184,6 @@ notes: AWS::Lambda::EventInvokeConfig: also what a SAM function's `EventInvokeConfig` expands into AWS::Lambda::WebFunction: control plane only; the endpoint domain does not serve requests yet AWS::Lambda::WebFunctionRevision: every property is createOnly, so a change mints a new revision - AWS::Lambda::WebFunctionEndpoint: '`RegionalEndpoints` is not exposed to `Fn::GetAtt` yet' AWS::EC2::VPC: 'deleted on stack teardown; a VPC with dependents outside the stack, including anything still holding a network interface in its subnets (an instance that is not terminated, a NAT gateway that is not deleted or failed, a standalone interface, an interface endpoint), fails the delete with `DependencyViolation`, as on AWS' AWS::EC2::SecurityGroup: inline `SecurityGroupIngress`/`SecurityGroupEgress` supported AWS::EC2::PrefixList: 'updated in place; an update that changes `AddressFamily`, or `MaxEntries` together with `Entries`, fails'