mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(lambda): provision AWS::Lambda::EventInvokeConfig (#3230)
* feat(lambda): provision AWS::Lambda::EventInvokeConfig The physical id is the registry schema's composite FunctionName|Qualifier identifier. A create puts the configuration, an update with the same identity applies the template's settings through the merge-style update call, and a changed function or qualifier is a replacement whose displaced configuration the ReplacementCleanup record deletes once the update commits or restores on rollback. The schema's MaximumRetryAttempts and MaximumEventAgeInSeconds bounds are checked before any call, as CloudFormation validates them before the handler runs. The Lambda docs now list the five event invoke config operations, which the page wrongly called not implemented, and say that asynchronous invocations do not yet apply the settings. * fix(lambda): update the event invoke config in place for equivalent names and roll back in-place changes A short name and the function's ARN address one configuration, so an update that changes between them updates in place under the prior physical id instead of recording a replacement whose cleanup would delete that one configuration. An in-place update keeps the settings it replaces on the resource, and a failed stack update puts them back in full. DestinationConfig is resolved before it is looked at, so a conditional that resolves to AWS::NoValue is omitted rather than sent as an empty destination set. The integration test reads stack events with XmlParser. * fix(lambda): keep the event invoke config rollback snapshot until the restore succeeds A restore that throws left no snapshot behind, so the next rollback attempt reported success without restoring anything. The snapshot is now spent only after the settings are back.
This commit is contained in:
1 parent
d9cddc56cb
commit
af42564cb3
9 files changed
+1435
-2
No files matched your search
+2
@@ -52,6 +52,7 @@ import io.github.hectorvent.floci.services.cloudformation.provisioners.IotDomain
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.KinesisCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.KmsCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaAddressingCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaEventInvokeConfigCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaEventSourceMappingCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LambdaVersionAliasCfnProvisioner;
|
||||
import io.github.hectorvent.floci.services.cloudformation.provisioners.LogsCfnProvisioner;
|
||||
@@ -266,6 +267,7 @@ final class CfnProvisionerFixture {
|
||||
}
|
||||
if (lambdaService != null) {
|
||||
discovered.add(new LambdaAddressingCfnProvisioner(lambdaService));
|
||||
discovered.add(new LambdaEventInvokeConfigCfnProvisioner(lambdaService));
|
||||
discovered.add(new LambdaVersionAliasCfnProvisioner(lambdaService));
|
||||
discovered.add(new LambdaEventSourceMappingCfnProvisioner(lambdaService));
|
||||
}
|
||||
|
||||
+337
@@ -0,0 +1,337 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.XmlParser;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Provisions an {@code AWS::Lambda::EventInvokeConfig} through a CloudFormation stack and reads
|
||||
* it back through the Lambda API. {@code Ref} is the composite {@code FunctionName|Qualifier} id
|
||||
* a real stack shows; a settings change updates the configuration in place; a qualifier change
|
||||
* replaces it, deleting the displaced configuration once the update commits; a failed update rolls
|
||||
* the replacement back; and the stack delete removes the configuration.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class CloudFormationLambdaEventInvokeConfigIntegrationTest {
|
||||
|
||||
private static final String CFN_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260908/us-east-1/cloudformation/aws4_request";
|
||||
private static final String DLQ_ARN = "arn:aws:sqs:us-east-1:000000000000:async-dlq";
|
||||
|
||||
/** The function and its first version, in a stack of their own so the configuration stacks hold nothing else. */
|
||||
private static final String FUNCTION_TEMPLATE = """
|
||||
{
|
||||
"Resources": {
|
||||
"Role": {
|
||||
"Type": "AWS::IAM::Role",
|
||||
"Properties": {
|
||||
"AssumeRolePolicyDocument": {"Version": "2012-10-17", "Statement": [
|
||||
{"Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, "Action": "sts:AssumeRole"}]}
|
||||
}
|
||||
},
|
||||
"Fn": {
|
||||
"Type": "AWS::Lambda::Function",
|
||||
"Properties": {
|
||||
"FunctionName": "%s",
|
||||
"Runtime": "python3.12",
|
||||
"Handler": "index.handler",
|
||||
"Role": {"Fn::GetAtt": ["Role", "Arn"]},
|
||||
"Code": {"ZipFile": "def handler(e, c): return 'ok'"}
|
||||
}
|
||||
},
|
||||
"Ver": {
|
||||
"Type": "AWS::Lambda::Version",
|
||||
"Properties": {"FunctionName": {"Ref": "Fn"}}
|
||||
}
|
||||
},
|
||||
"Outputs": {
|
||||
"Version": {"Value": {"Fn::GetAtt": ["Ver", "Version"]}}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
private static final String CONFIG_TEMPLATE = """
|
||||
{
|
||||
"Parameters": {
|
||||
"Qualifier": {"Type": "String", "Default": "$LATEST"},
|
||||
"Retries": {"Type": "String", "Default": "1"}
|
||||
},
|
||||
"Resources": {
|
||||
"AsyncConfig": {
|
||||
"Type": "AWS::Lambda::EventInvokeConfig",
|
||||
"Properties": {
|
||||
"FunctionName": "%s",
|
||||
"Qualifier": {"Ref": "Qualifier"},
|
||||
"MaximumRetryAttempts": {"Ref": "Retries"},
|
||||
"MaximumEventAgeInSeconds": 300,
|
||||
"DestinationConfig": {"OnFailure": {"Destination": "%s"}}
|
||||
}
|
||||
}%s
|
||||
},
|
||||
"Outputs": {
|
||||
"ConfigRef": {"Value": {"Ref": "AsyncConfig"}}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
/** A resource that fails after the configuration, so the update rolls the replacement back. */
|
||||
private static final String FAILING_RESOURCE = """
|
||||
,
|
||||
"BadSecret": {
|
||||
"Type": "AWS::SecretsManager::Secret",
|
||||
"DependsOn": "AsyncConfig",
|
||||
"Properties": {
|
||||
"Name": "event-invoke-rollback-%s",
|
||||
"SecretString": "explicit",
|
||||
"GenerateSecretString": {"PasswordLength": 32}
|
||||
}
|
||||
}""";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void configurationFollowsTheTemplateThroughCreateUpdateReplacementAndDelete() throws InterruptedException {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String functionStack = "cfn-event-invoke-fn-" + suffix;
|
||||
String stack = "cfn-event-invoke-" + suffix;
|
||||
String fn = "event-invoke-fn-" + suffix;
|
||||
String version = createFunctionStack(functionStack, fn);
|
||||
String template = CONFIG_TEMPLATE.formatted(fn, DLQ_ARN, "");
|
||||
|
||||
cloudFormation(stack, "CreateStack", template, Map.of());
|
||||
assertEquals(fn + "|$LATEST", outputValue(describeStacks(stack, "CREATE_COMPLETE"), "ConfigRef"),
|
||||
"Ref is the composite FunctionName|Qualifier identifier");
|
||||
getConfig(fn, "$LATEST").then()
|
||||
.statusCode(200)
|
||||
.body("FunctionArn", containsString(":function:" + fn + ":$LATEST"))
|
||||
.body("MaximumRetryAttempts", equalTo(1))
|
||||
.body("MaximumEventAgeInSeconds", equalTo(300))
|
||||
.body("DestinationConfig.OnFailure.Destination", equalTo(DLQ_ARN))
|
||||
.body("DestinationConfig.OnSuccess", nullValue());
|
||||
|
||||
cloudFormation(stack, "UpdateStack", template, Map.of("Retries", "0"));
|
||||
assertEquals(fn + "|$LATEST", outputValue(describeStacks(stack, "UPDATE_COMPLETE"), "ConfigRef"),
|
||||
"a settings change keeps the same configuration");
|
||||
getConfig(fn, "$LATEST").then()
|
||||
.statusCode(200)
|
||||
.body("MaximumRetryAttempts", equalTo(0))
|
||||
.body("MaximumEventAgeInSeconds", equalTo(300))
|
||||
.body("DestinationConfig.OnFailure.Destination", equalTo(DLQ_ARN));
|
||||
|
||||
cloudFormation(stack, "UpdateStack", template, Map.of("Retries", "0", "Qualifier", version));
|
||||
assertEquals(fn + "|" + version, outputValue(describeStacks(stack, "UPDATE_COMPLETE"), "ConfigRef"),
|
||||
"a qualifier change is a replacement");
|
||||
getConfig(fn, version).then()
|
||||
.statusCode(200)
|
||||
.body("FunctionArn", containsString(":function:" + fn + ":" + version))
|
||||
.body("MaximumRetryAttempts", equalTo(0));
|
||||
getConfig(fn, "$LATEST").then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
assertEvent(describeEvents(stack), "DELETE_COMPLETE", fn + "|$LATEST");
|
||||
|
||||
cloudFormation(stack, "DeleteStack", null, Map.of());
|
||||
awaitStackDeleted(stack);
|
||||
getConfig(fn, version).then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
given().when().get("/2015-03-31/functions/" + fn).then().statusCode(200);
|
||||
|
||||
cloudFormation(functionStack, "DeleteStack", null, Map.of());
|
||||
awaitStackDeleted(functionStack);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFailedUpdateRollsTheReplacementBack() throws InterruptedException {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String functionStack = "cfn-event-invoke-rb-fn-" + suffix;
|
||||
String stack = "cfn-event-invoke-rb-" + suffix;
|
||||
String fn = "event-invoke-rb-fn-" + suffix;
|
||||
String version = createFunctionStack(functionStack, fn);
|
||||
|
||||
cloudFormation(stack, "CreateStack", CONFIG_TEMPLATE.formatted(fn, DLQ_ARN, ""), Map.of());
|
||||
describeStacks(stack, "CREATE_COMPLETE");
|
||||
|
||||
cloudFormation(stack, "UpdateStack", CONFIG_TEMPLATE.formatted(fn, DLQ_ARN, FAILING_RESOURCE.formatted(suffix)),
|
||||
Map.of("Qualifier", version));
|
||||
String rolledBack = describeStacks(stack, "UPDATE_ROLLBACK_COMPLETE");
|
||||
assertEquals(fn + "|$LATEST", outputValue(rolledBack, "ConfigRef"),
|
||||
"the resource names the prior configuration again");
|
||||
getConfig(fn, "$LATEST").then()
|
||||
.statusCode(200)
|
||||
.body("MaximumRetryAttempts", equalTo(1));
|
||||
getConfig(fn, version).then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
cloudFormation(stack, "DeleteStack", null, Map.of());
|
||||
awaitStackDeleted(stack);
|
||||
cloudFormation(functionStack, "DeleteStack", null, Map.of());
|
||||
awaitStackDeleted(functionStack);
|
||||
}
|
||||
|
||||
/** An in-place settings change is put back from the snapshot the update took. */
|
||||
@Test
|
||||
void aFailedUpdateRestoresTheSettingsAnInPlaceUpdateChanged() throws InterruptedException {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String functionStack = "cfn-event-invoke-ip-fn-" + suffix;
|
||||
String stack = "cfn-event-invoke-ip-" + suffix;
|
||||
String fn = "event-invoke-ip-fn-" + suffix;
|
||||
createFunctionStack(functionStack, fn);
|
||||
|
||||
cloudFormation(stack, "CreateStack", CONFIG_TEMPLATE.formatted(fn, DLQ_ARN, ""), Map.of());
|
||||
describeStacks(stack, "CREATE_COMPLETE");
|
||||
|
||||
cloudFormation(stack, "UpdateStack", CONFIG_TEMPLATE.formatted(fn, DLQ_ARN, FAILING_RESOURCE.formatted(suffix)),
|
||||
Map.of("Retries", "0"));
|
||||
String rolledBack = describeStacks(stack, "UPDATE_ROLLBACK_COMPLETE");
|
||||
assertEquals(fn + "|$LATEST", outputValue(rolledBack, "ConfigRef"));
|
||||
getConfig(fn, "$LATEST").then()
|
||||
.statusCode(200)
|
||||
.body("MaximumRetryAttempts", equalTo(1))
|
||||
.body("MaximumEventAgeInSeconds", equalTo(300))
|
||||
.body("DestinationConfig.OnFailure.Destination", equalTo(DLQ_ARN));
|
||||
|
||||
cloudFormation(stack, "DeleteStack", null, Map.of());
|
||||
awaitStackDeleted(stack);
|
||||
cloudFormation(functionStack, "DeleteStack", null, Map.of());
|
||||
awaitStackDeleted(functionStack);
|
||||
}
|
||||
|
||||
@Test
|
||||
void anOutOfRangeSettingFailsTheResource() throws InterruptedException {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String functionStack = "cfn-event-invoke-bad-fn-" + suffix;
|
||||
String stack = "cfn-event-invoke-bad-" + suffix;
|
||||
String fn = "event-invoke-bad-fn-" + suffix;
|
||||
createFunctionStack(functionStack, fn);
|
||||
|
||||
cloudFormation(stack, "CreateStack", CONFIG_TEMPLATE.formatted(fn, DLQ_ARN, ""), Map.of("Retries", "3"));
|
||||
|
||||
String failed = awaitStackStatus(stack, "ROLLBACK_COMPLETE");
|
||||
assertTrue(failed.contains("MaximumRetryAttempts"),
|
||||
"the status reason names the property: " + failed);
|
||||
getConfig(fn, "$LATEST").then().statusCode(404);
|
||||
|
||||
cloudFormation(stack, "DeleteStack", null, Map.of());
|
||||
awaitStackDeleted(stack);
|
||||
cloudFormation(functionStack, "DeleteStack", null, Map.of());
|
||||
awaitStackDeleted(functionStack);
|
||||
}
|
||||
|
||||
/** Creates the function stack and returns the number of the version it published. */
|
||||
private static String createFunctionStack(String stack, String fn) {
|
||||
cloudFormation(stack, "CreateStack", FUNCTION_TEMPLATE.formatted(fn), Map.of());
|
||||
return outputValue(describeStacks(stack, "CREATE_COMPLETE"), "Version");
|
||||
}
|
||||
|
||||
private static Response getConfig(String functionName, String qualifier) {
|
||||
return given()
|
||||
.queryParam("Qualifier", qualifier)
|
||||
.when().get("/2019-09-25/functions/" + functionName + "/event-invoke-config");
|
||||
}
|
||||
|
||||
private static void cloudFormation(String stack, String action, String templateBody,
|
||||
Map<String, String> parameters) {
|
||||
RequestSpecification request = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", action)
|
||||
.formParam("StackName", stack)
|
||||
.formParam("Capabilities.member.1", "CAPABILITY_IAM");
|
||||
if (templateBody != null) {
|
||||
request.formParam("TemplateBody", templateBody);
|
||||
}
|
||||
int index = 1;
|
||||
for (Map.Entry<String, String> parameter : parameters.entrySet()) {
|
||||
request.formParam("Parameters.member." + index + ".ParameterKey", parameter.getKey());
|
||||
request.formParam("Parameters.member." + index + ".ParameterValue", parameter.getValue());
|
||||
index++;
|
||||
}
|
||||
request.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
private static String describeStacks(String stack, String expectedStatus) {
|
||||
return given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stack)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<StackStatus>" + expectedStatus + "</StackStatus>"))
|
||||
.extract().asString();
|
||||
}
|
||||
|
||||
private static String describeEvents(String stack) {
|
||||
return given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DescribeStackEvents")
|
||||
.formParam("StackName", stack)
|
||||
.when().post("/").then().statusCode(200).extract().asString();
|
||||
}
|
||||
|
||||
private static void assertEvent(String eventsXml, String status, String physicalId) {
|
||||
boolean found = XmlParser.extractGroups(eventsXml, "member").stream()
|
||||
.anyMatch(event -> status.equals(event.get("ResourceStatus"))
|
||||
&& physicalId.equals(event.get("PhysicalResourceId")));
|
||||
assertTrue(found, "no " + status + " event for " + physicalId + " in " + eventsXml);
|
||||
}
|
||||
|
||||
/** A failed create rolls back asynchronously; returns the events once the status is reached. */
|
||||
private static String awaitStackStatus(String stack, String expectedStatus) throws InterruptedException {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String body = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stack)
|
||||
.when().post("/").then().extract().asString();
|
||||
if (body.contains("<StackStatus>" + expectedStatus + "</StackStatus>")) {
|
||||
return describeEvents(stack);
|
||||
}
|
||||
Thread.sleep(50);
|
||||
}
|
||||
return fail("stack " + stack + " did not reach " + expectedStatus + " within the timeout");
|
||||
}
|
||||
|
||||
private static void awaitStackDeleted(String stack) throws InterruptedException {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
String body = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", CFN_AUTH)
|
||||
.formParam("Action", "DescribeStacks")
|
||||
.formParam("StackName", stack)
|
||||
.when().post("/").then().extract().asString();
|
||||
if (body.contains("does not exist")) {
|
||||
return;
|
||||
}
|
||||
if (body.contains("<StackStatus>DELETE_FAILED</StackStatus>")) {
|
||||
fail("stack delete failed: " + body);
|
||||
}
|
||||
Thread.sleep(50);
|
||||
}
|
||||
fail("stack " + stack + " was not deleted within the timeout");
|
||||
}
|
||||
|
||||
private static String outputValue(String xml, String key) {
|
||||
return XmlParser.extractPairs(xml, "Outputs", "OutputKey", "OutputValue").get(key);
|
||||
}
|
||||
}
|
||||
+527
@@ -0,0 +1,527 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation.provisioners;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.TextNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
|
||||
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaService;
|
||||
import io.github.hectorvent.floci.services.lambda.model.FunctionEventInvokeConfig;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyMap;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* {@code AWS::Lambda::EventInvokeConfig}: the physical id is the schema's composite identifier,
|
||||
* a create keeps only the properties the template names, an update with the same identity goes
|
||||
* through the merge-style update call, and a changed identity is a replacement whose displaced
|
||||
* configuration is left to the cleanup record.
|
||||
*/
|
||||
class LambdaEventInvokeConfigCfnProvisionerTest {
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT_ID = "000000000000";
|
||||
private static final String STACK = "my-stack";
|
||||
private static final String TYPE = "AWS::Lambda::EventInvokeConfig";
|
||||
|
||||
private LambdaService lambda;
|
||||
private LambdaEventInvokeConfigCfnProvisioner provisioner;
|
||||
private CloudFormationTemplateEngine engine;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
lambda = mock(LambdaService.class);
|
||||
provisioner = new LambdaEventInvokeConfigCfnProvisioner(lambda);
|
||||
engine = mock(CloudFormationTemplateEngine.class);
|
||||
when(engine.resolve(any())).thenAnswer(i -> {
|
||||
JsonNode node = i.getArgument(0);
|
||||
return node == null || node.isMissingNode() || node.isNull() ? null : node.asText();
|
||||
});
|
||||
when(engine.resolveNode(any())).thenAnswer(i -> i.getArgument(0));
|
||||
// The service never answers null: a missing configuration throws. Tests that care about
|
||||
// the settings before an update stub their own.
|
||||
when(lambda.getEventInvokeConfig(anyString(), anyString(), anyString()))
|
||||
.thenReturn(config(2, 21600, null, null));
|
||||
}
|
||||
|
||||
private static JsonNode props(String json) {
|
||||
try {
|
||||
return MAPPER.readTree(json);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static StackResource resource() {
|
||||
StackResource r = new StackResource();
|
||||
r.setLogicalId("AsyncConfig");
|
||||
r.setResourceType(TYPE);
|
||||
return r;
|
||||
}
|
||||
|
||||
private StackResource provision(String json, String priorPhysicalId) {
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId(priorPhysicalId);
|
||||
r.setAttributes(new HashMap<>());
|
||||
provisioner.provision(r, props(json),
|
||||
new ProvisionContext(engine, REGION, ACCOUNT_ID, STACK, priorPhysicalId));
|
||||
return r;
|
||||
}
|
||||
|
||||
@Test
|
||||
void servesOnlyTheEventInvokeConfigType() {
|
||||
assertEquals(Set.of(TYPE), provisioner.resourceTypes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createPutsTheConfigurationAndJoinsTheIdentityWithAPipe() {
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "$LATEST",
|
||||
"MaximumRetryAttempts": 1, "MaximumEventAgeInSeconds": 300,
|
||||
"DestinationConfig": {
|
||||
"OnSuccess": {"Destination": "arn:aws:sqs:us-east-1:000000000000:ok"},
|
||||
"OnFailure": {"Destination": "arn:aws:sqs:us-east-1:000000000000:dlq"}}}
|
||||
""", null);
|
||||
|
||||
ArgumentCaptor<Map<String, Object>> request = ArgumentCaptor.captor();
|
||||
verify(lambda).putEventInvokeConfig(eq(REGION), eq("orders"), eq("$LATEST"), request.capture());
|
||||
verify(lambda, never()).updateEventInvokeConfig(anyString(), anyString(), anyString(), anyMap());
|
||||
assertEquals(1, request.getValue().get("MaximumRetryAttempts"));
|
||||
assertEquals(300, request.getValue().get("MaximumEventAgeInSeconds"));
|
||||
assertEquals(Map.of(
|
||||
"OnSuccess", Map.of("Destination", "arn:aws:sqs:us-east-1:000000000000:ok"),
|
||||
"OnFailure", Map.of("Destination", "arn:aws:sqs:us-east-1:000000000000:dlq")),
|
||||
request.getValue().get("DestinationConfig"));
|
||||
assertEquals("orders|$LATEST", r.getPhysicalId(), "Ref is FunctionName|Qualifier");
|
||||
assertTrue(r.getAttributes().isEmpty(), "the schema declares no Fn::GetAtt attributes");
|
||||
assertFalse(provisioner.hasReplacementUpdate(r));
|
||||
}
|
||||
|
||||
/** Numbers arrive as strings after intrinsic resolution as often as they arrive as numbers. */
|
||||
@Test
|
||||
void numericSettingsGivenAsStringsAreParsed() {
|
||||
provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "live",
|
||||
"MaximumRetryAttempts": "0", "MaximumEventAgeInSeconds": "60"}
|
||||
""", null);
|
||||
|
||||
ArgumentCaptor<Map<String, Object>> request = ArgumentCaptor.captor();
|
||||
verify(lambda).putEventInvokeConfig(eq(REGION), eq("orders"), eq("live"), request.capture());
|
||||
assertEquals(0, request.getValue().get("MaximumRetryAttempts"));
|
||||
assertEquals(60, request.getValue().get("MaximumEventAgeInSeconds"));
|
||||
}
|
||||
|
||||
/** A setting the template leaves out is left out of the request; the service stores nothing for it. */
|
||||
@Test
|
||||
void omittedSettingsAreNotSent() {
|
||||
provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "3"}
|
||||
""", null);
|
||||
|
||||
ArgumentCaptor<Map<String, Object>> request = ArgumentCaptor.captor();
|
||||
verify(lambda).putEventInvokeConfig(eq(REGION), eq("orders"), eq("3"), request.capture());
|
||||
assertTrue(request.getValue().isEmpty(), "no setting means an empty request: " + request.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aDestinationSideThatIsOmittedIsNotSent() {
|
||||
provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "live",
|
||||
"DestinationConfig": {"OnFailure": {"Destination": "arn:aws:sns:us-east-1:000000000000:alerts"}}}
|
||||
""", null);
|
||||
|
||||
ArgumentCaptor<Map<String, Object>> request = ArgumentCaptor.captor();
|
||||
verify(lambda).putEventInvokeConfig(eq(REGION), eq("orders"), eq("live"), request.capture());
|
||||
assertEquals(Map.of("OnFailure", Map.of("Destination", "arn:aws:sns:us-east-1:000000000000:alerts")),
|
||||
request.getValue().get("DestinationConfig"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void functionNameIsRequired() {
|
||||
AwsException e = assertThrows(AwsException.class, () -> provision("""
|
||||
{"Qualifier": "$LATEST"}
|
||||
""", null));
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode());
|
||||
assertTrue(e.getMessage().contains("FunctionName"), e.getMessage());
|
||||
verifyNoInteractions(lambda);
|
||||
}
|
||||
|
||||
@Test
|
||||
void qualifierIsRequired() {
|
||||
AwsException e = assertThrows(AwsException.class, () -> provision("""
|
||||
{"FunctionName": "orders"}
|
||||
""", null));
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode());
|
||||
assertTrue(e.getMessage().contains("Qualifier"), e.getMessage());
|
||||
verifyNoInteractions(lambda);
|
||||
}
|
||||
|
||||
/** The registry schema caps MaximumRetryAttempts at 0..2; CloudFormation rejects the template before any call. */
|
||||
@Test
|
||||
void retryAttemptsOutsideTheSchemaRangeAreRejectedBeforeAnyCall() {
|
||||
for (String value : new String[] {"-1", "3", "two"}) {
|
||||
AwsException e = assertThrows(AwsException.class, () -> provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "$LATEST", "MaximumRetryAttempts": "%s"}
|
||||
""".formatted(value), null), value);
|
||||
assertEquals("ValidationError", e.getErrorCode(), value);
|
||||
assertTrue(e.getMessage().contains("MaximumRetryAttempts"), e.getMessage());
|
||||
}
|
||||
verifyNoInteractions(lambda);
|
||||
}
|
||||
|
||||
/** MaximumEventAgeInSeconds is 60..21600 in the schema. */
|
||||
@Test
|
||||
void eventAgeOutsideTheSchemaRangeIsRejectedBeforeAnyCall() {
|
||||
for (String value : new String[] {"59", "21601", "1h"}) {
|
||||
AwsException e = assertThrows(AwsException.class, () -> provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "$LATEST", "MaximumEventAgeInSeconds": "%s"}
|
||||
""".formatted(value), null), value);
|
||||
assertEquals("ValidationError", e.getErrorCode(), value);
|
||||
assertTrue(e.getMessage().contains("MaximumEventAgeInSeconds"), e.getMessage());
|
||||
}
|
||||
verifyNoInteractions(lambda);
|
||||
}
|
||||
|
||||
@Test
|
||||
void theRangeBoundsThemselvesAreAccepted() {
|
||||
provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "$LATEST",
|
||||
"MaximumRetryAttempts": 2, "MaximumEventAgeInSeconds": 21600}
|
||||
""", null);
|
||||
|
||||
ArgumentCaptor<Map<String, Object>> request = ArgumentCaptor.captor();
|
||||
verify(lambda).putEventInvokeConfig(eq(REGION), eq("orders"), eq("$LATEST"), request.capture());
|
||||
assertEquals(2, request.getValue().get("MaximumRetryAttempts"));
|
||||
assertEquals(21600, request.getValue().get("MaximumEventAgeInSeconds"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aDestinationWithoutAnArnIsRejected() {
|
||||
AwsException e = assertThrows(AwsException.class, () -> provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "$LATEST",
|
||||
"DestinationConfig": {"OnFailure": {}}}
|
||||
""", null));
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode());
|
||||
assertTrue(e.getMessage().contains("Destination"), e.getMessage());
|
||||
verifyNoInteractions(lambda);
|
||||
}
|
||||
|
||||
/** Same function and qualifier: the update path, applied through the merge-style update call. */
|
||||
@Test
|
||||
void anUpdateWithTheSameIdentityUpdatesInPlace() {
|
||||
when(lambda.getEventInvokeConfig(REGION, "orders", "$LATEST")).thenReturn(config(2, 21600, null, null));
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "$LATEST", "MaximumRetryAttempts": 0}
|
||||
""", "orders|$LATEST");
|
||||
|
||||
ArgumentCaptor<Map<String, Object>> request = ArgumentCaptor.captor();
|
||||
verify(lambda).updateEventInvokeConfig(eq(REGION), eq("orders"), eq("$LATEST"), request.capture());
|
||||
verify(lambda, never()).putEventInvokeConfig(anyString(), anyString(), anyString(), anyMap());
|
||||
assertEquals(Map.of("MaximumRetryAttempts", 0), request.getValue());
|
||||
assertEquals("orders|$LATEST", r.getPhysicalId());
|
||||
assertFalse(provisioner.hasReplacementUpdate(r));
|
||||
assertNull(provisioner.updateCleanupPhysicalId(r));
|
||||
}
|
||||
|
||||
/** Both identifier parts are create-only: changing the qualifier creates a new configuration. */
|
||||
@Test
|
||||
void aChangedQualifierIsAReplacementThatLeavesThePriorToTheCleanup() {
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "live", "MaximumRetryAttempts": 1}
|
||||
""", "orders|$LATEST");
|
||||
|
||||
verify(lambda).putEventInvokeConfig(eq(REGION), eq("orders"), eq("live"), anyMap());
|
||||
verify(lambda, never()).updateEventInvokeConfig(anyString(), anyString(), anyString(), anyMap());
|
||||
verify(lambda, never()).deleteEventInvokeConfig(anyString(), anyString(), anyString());
|
||||
assertEquals("orders|live", r.getPhysicalId());
|
||||
assertTrue(provisioner.hasReplacementUpdate(r));
|
||||
assertEquals("orders|$LATEST", provisioner.updateCleanupPhysicalId(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aChangedFunctionIsAReplacement() {
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "payments", "Qualifier": "$LATEST"}
|
||||
""", "orders|$LATEST");
|
||||
|
||||
verify(lambda).putEventInvokeConfig(eq(REGION), eq("payments"), eq("$LATEST"), anyMap());
|
||||
assertEquals("payments|$LATEST", r.getPhysicalId());
|
||||
assertEquals("orders|$LATEST", provisioner.updateCleanupPhysicalId(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
void completingAReplacementDeletesTheDisplacedConfiguration() {
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "live"}
|
||||
""", "orders|$LATEST");
|
||||
|
||||
UpdateCleanupResult result = provisioner.completeUpdate(r);
|
||||
|
||||
assertTrue(result.applicable());
|
||||
assertTrue(result.complete());
|
||||
verify(lambda).deleteEventInvokeConfig(REGION, "orders", "$LATEST");
|
||||
assertFalse(provisioner.hasReplacementUpdate(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rollingBackAReplacementDeletesTheNewConfigurationAndRestoresThePriorId() {
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "live"}
|
||||
""", "orders|$LATEST");
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
|
||||
verify(lambda).deleteEventInvokeConfig(REGION, "orders", "live");
|
||||
verify(lambda, never()).deleteEventInvokeConfig(REGION, "orders", "$LATEST");
|
||||
assertEquals("orders|$LATEST", r.getPhysicalId());
|
||||
assertFalse(provisioner.hasReplacementUpdate(r));
|
||||
}
|
||||
|
||||
/**
|
||||
* The service keys a configuration by the function's ARN, so a short name and the ARN address
|
||||
* one configuration: treating the change as a replacement would put over that configuration
|
||||
* and then delete it through the old name once the update committed.
|
||||
*/
|
||||
@Test
|
||||
void aFunctionNameGivenAsTheArnOfTheSameFunctionUpdatesInPlace() {
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "arn:aws:lambda:us-east-1:000000000000:function:orders", "Qualifier": "$LATEST",
|
||||
"MaximumRetryAttempts": 0}
|
||||
""", "orders|$LATEST");
|
||||
|
||||
verify(lambda).updateEventInvokeConfig(eq(REGION),
|
||||
eq("arn:aws:lambda:us-east-1:000000000000:function:orders"), eq("$LATEST"), anyMap());
|
||||
verify(lambda, never()).putEventInvokeConfig(anyString(), anyString(), anyString(), anyMap());
|
||||
assertEquals("orders|$LATEST", r.getPhysicalId(), "the prior id stays so nothing is recorded as displaced");
|
||||
assertFalse(provisioner.hasReplacementUpdate(r));
|
||||
assertNull(provisioner.updateCleanupPhysicalId(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theSameNameInAnotherRegionIsAnotherTarget() {
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "arn:aws:lambda:eu-west-1:000000000000:function:orders", "Qualifier": "$LATEST"}
|
||||
""", "arn:aws:lambda:us-east-1:000000000000:function:orders|$LATEST");
|
||||
|
||||
verify(lambda).putEventInvokeConfig(eq(REGION),
|
||||
eq("arn:aws:lambda:eu-west-1:000000000000:function:orders"), eq("$LATEST"), anyMap());
|
||||
assertTrue(provisioner.hasReplacementUpdate(r));
|
||||
}
|
||||
|
||||
/** The settings before an in-place update are kept, and a failed stack update puts every one back. */
|
||||
@Test
|
||||
void anInPlaceUpdateIsRolledBackFromTheSettingsItReplaced() {
|
||||
when(lambda.getEventInvokeConfig(REGION, "orders", "$LATEST")).thenReturn(config(2, 21600,
|
||||
"arn:aws:sqs:us-east-1:000000000000:ok", "arn:aws:sqs:us-east-1:000000000000:dlq"));
|
||||
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "$LATEST", "MaximumRetryAttempts": 0,
|
||||
"DestinationConfig": {"OnFailure": {"Destination": "arn:aws:sns:us-east-1:000000000000:alerts"}}}
|
||||
""", "orders|$LATEST");
|
||||
assertTrue(r.getAttributes().containsKey(CfnRollback.EVENT_INVOKE_CONFIG_SNAPSHOT_ATTR));
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
|
||||
ArgumentCaptor<Map<String, Object>> restored = ArgumentCaptor.captor();
|
||||
verify(lambda).putEventInvokeConfig(eq(REGION), eq("orders"), eq("$LATEST"), restored.capture());
|
||||
assertEquals(2, restored.getValue().get("MaximumRetryAttempts"));
|
||||
assertEquals(21600, restored.getValue().get("MaximumEventAgeInSeconds"));
|
||||
assertEquals(Map.of(
|
||||
"OnSuccess", Map.of("Destination", "arn:aws:sqs:us-east-1:000000000000:ok"),
|
||||
"OnFailure", Map.of("Destination", "arn:aws:sqs:us-east-1:000000000000:dlq")),
|
||||
restored.getValue().get("DestinationConfig"));
|
||||
assertFalse(r.getAttributes().containsKey(CfnRollback.EVENT_INVOKE_CONFIG_SNAPSHOT_ATTR),
|
||||
"the snapshot is spent by the rollback");
|
||||
}
|
||||
|
||||
/** A restore that fails keeps the snapshot, so the next rollback attempt still has it. */
|
||||
@Test
|
||||
void aFailedRestoreKeepsTheSnapshot() {
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "$LATEST", "MaximumRetryAttempts": 0}
|
||||
""", "orders|$LATEST");
|
||||
doThrow(new AwsException("ServiceException", "boom", 500))
|
||||
.when(lambda).putEventInvokeConfig(eq(REGION), eq("orders"), eq("$LATEST"), anyMap());
|
||||
|
||||
assertThrows(AwsException.class, () -> provisioner.rollbackUpdate(r));
|
||||
|
||||
assertTrue(r.getAttributes().containsKey(CfnRollback.EVENT_INVOKE_CONFIG_SNAPSHOT_ATTR));
|
||||
}
|
||||
|
||||
/** Settings the configuration did not carry are restored as absent, not as defaults. */
|
||||
@Test
|
||||
void rollbackRestoresAbsentSettingsAsAbsent() {
|
||||
when(lambda.getEventInvokeConfig(REGION, "orders", "live")).thenReturn(config(null, null, null, null));
|
||||
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "live", "MaximumEventAgeInSeconds": 120}
|
||||
""", "orders|live");
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
|
||||
ArgumentCaptor<Map<String, Object>> restored = ArgumentCaptor.captor();
|
||||
verify(lambda).putEventInvokeConfig(eq(REGION), eq("orders"), eq("live"), restored.capture());
|
||||
assertTrue(restored.getValue().isEmpty(), restored.getValue().toString());
|
||||
}
|
||||
|
||||
/** A successful update clears the snapshot, so a later rollback cannot restore stale settings. */
|
||||
@Test
|
||||
void aCommittedUpdateDropsTheSnapshot() {
|
||||
when(lambda.getEventInvokeConfig(REGION, "orders", "$LATEST")).thenReturn(config(2, 21600, null, null));
|
||||
StackResource r = provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "$LATEST", "MaximumRetryAttempts": 0}
|
||||
""", "orders|$LATEST");
|
||||
|
||||
provisioner.clearUpdate(r);
|
||||
|
||||
assertFalse(r.getAttributes().containsKey(CfnRollback.EVENT_INVOKE_CONFIG_SNAPSHOT_ATTR));
|
||||
assertTrue(provisioner.rollbackUpdate(r), "nothing is left to undo");
|
||||
verify(lambda, never()).putEventInvokeConfig(anyString(), anyString(), anyString(), anyMap());
|
||||
}
|
||||
|
||||
/** A provision that failed before it changed anything has nothing to undo. */
|
||||
@Test
|
||||
void aProvisionThatFailedBeforeMutatingReportsRolledBack() {
|
||||
doThrow(new AwsException("ResourceNotFoundException", "Function not found: payments", 404))
|
||||
.when(lambda).putEventInvokeConfig(eq(REGION), eq("payments"), eq("$LATEST"), anyMap());
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId("orders|$LATEST");
|
||||
assertThrows(AwsException.class, () -> provisioner.provision(r, props("""
|
||||
{"FunctionName": "payments", "Qualifier": "$LATEST"}
|
||||
"""), new ProvisionContext(engine, REGION, ACCOUNT_ID, STACK, "orders|$LATEST")));
|
||||
|
||||
assertTrue(provisioner.rollbackUpdate(r));
|
||||
verify(lambda, never()).deleteEventInvokeConfig(anyString(), anyString(), anyString());
|
||||
}
|
||||
|
||||
/** A conditional DestinationConfig that resolves to AWS::NoValue is omitted, not sent as an empty set. */
|
||||
@Test
|
||||
void aDestinationConfigResolvingToNoValueIsNotSent() {
|
||||
when(engine.resolveNode(any())).thenAnswer(i -> {
|
||||
JsonNode node = i.getArgument(0);
|
||||
return node.has("Ref") ? TextNode.valueOf("") : node;
|
||||
});
|
||||
|
||||
provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "$LATEST",
|
||||
"DestinationConfig": {"Ref": "AWS::NoValue"}}
|
||||
""", "orders|$LATEST");
|
||||
|
||||
ArgumentCaptor<Map<String, Object>> request = ArgumentCaptor.captor();
|
||||
verify(lambda).updateEventInvokeConfig(eq(REGION), eq("orders"), eq("$LATEST"), request.capture());
|
||||
assertFalse(request.getValue().containsKey("DestinationConfig"), request.getValue().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aDestinationSideResolvingToNoValueIsNotSent() {
|
||||
when(engine.resolveNode(any())).thenAnswer(i -> {
|
||||
JsonNode node = i.getArgument(0);
|
||||
if (node.isObject() && node.has("OnSuccess")) {
|
||||
((com.fasterxml.jackson.databind.node.ObjectNode) node).set("OnSuccess", TextNode.valueOf(""));
|
||||
}
|
||||
return node;
|
||||
});
|
||||
|
||||
provision("""
|
||||
{"FunctionName": "orders", "Qualifier": "$LATEST",
|
||||
"DestinationConfig": {"OnSuccess": {"Ref": "AWS::NoValue"},
|
||||
"OnFailure": {"Destination": "arn:aws:sqs:us-east-1:000000000000:dlq"}}}
|
||||
""", null);
|
||||
|
||||
ArgumentCaptor<Map<String, Object>> request = ArgumentCaptor.captor();
|
||||
verify(lambda).putEventInvokeConfig(eq(REGION), eq("orders"), eq("$LATEST"), request.capture());
|
||||
assertEquals(Map.of("OnFailure", Map.of("Destination", "arn:aws:sqs:us-east-1:000000000000:dlq")),
|
||||
request.getValue().get("DestinationConfig"));
|
||||
}
|
||||
|
||||
private static FunctionEventInvokeConfig config(Integer retries, Integer eventAge,
|
||||
String onSuccess, String onFailure) {
|
||||
FunctionEventInvokeConfig config = new FunctionEventInvokeConfig();
|
||||
config.setFunctionArn("arn:aws:lambda:us-east-1:000000000000:function:orders:$LATEST");
|
||||
config.setMaximumRetryAttempts(retries);
|
||||
config.setMaximumEventAgeInSeconds(eventAge);
|
||||
if (onSuccess != null || onFailure != null) {
|
||||
FunctionEventInvokeConfig.DestinationConfig destinations = new FunctionEventInvokeConfig.DestinationConfig();
|
||||
if (onSuccess != null) {
|
||||
destinations.setOnSuccess(new FunctionEventInvokeConfig.Destination(onSuccess));
|
||||
}
|
||||
if (onFailure != null) {
|
||||
destinations.setOnFailure(new FunctionEventInvokeConfig.Destination(onFailure));
|
||||
}
|
||||
config.setDestinationConfig(destinations);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFailedPutLeavesThePriorIdInPlace() {
|
||||
doThrow(new AwsException("ResourceNotFoundException", "Function not found: payments", 404))
|
||||
.when(lambda).putEventInvokeConfig(eq(REGION), eq("payments"), eq("$LATEST"), anyMap());
|
||||
|
||||
StackResource r = resource();
|
||||
r.setPhysicalId("orders|$LATEST");
|
||||
assertThrows(AwsException.class, () -> provisioner.provision(r, props("""
|
||||
{"FunctionName": "payments", "Qualifier": "$LATEST"}
|
||||
"""), new ProvisionContext(engine, REGION, ACCOUNT_ID, STACK, "orders|$LATEST")));
|
||||
|
||||
assertEquals("orders|$LATEST", r.getPhysicalId());
|
||||
assertFalse(provisioner.hasReplacementUpdate(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteSplitsTheIdentityAtThePipe() {
|
||||
provisioner.delete(TYPE, "arn:aws:lambda:us-east-1:000000000000:function:orders|live", REGION);
|
||||
|
||||
verify(lambda).deleteEventInvokeConfig(REGION,
|
||||
"arn:aws:lambda:us-east-1:000000000000:function:orders", "live");
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteToleratesAConfigurationThatIsAlreadyGone() {
|
||||
doThrow(new AwsException("ResourceNotFoundException",
|
||||
"The function arn:aws:lambda:us-east-1:000000000000:function:orders doesn't have an EventInvokeConfig", 404))
|
||||
.when(lambda).deleteEventInvokeConfig(REGION, "orders", "$LATEST");
|
||||
|
||||
provisioner.delete(TYPE, "orders|$LATEST", REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletePropagatesAnyOtherFailure() {
|
||||
doThrow(new AwsException("ServiceException", "boom", 500))
|
||||
.when(lambda).deleteEventInvokeConfig(REGION, "orders", "$LATEST");
|
||||
|
||||
assertThrows(AwsException.class, () -> provisioner.delete(TYPE, "orders|$LATEST", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteIgnoresAnIdWithoutAQualifier() {
|
||||
provisioner.delete(TYPE, "orders", REGION);
|
||||
provisioner.delete(TYPE, null, REGION);
|
||||
|
||||
verifyNoInteractions(lambda);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user