feat(lambdaweb): CloudFormation types for Lambda Web Functions (#5722)

* feat(lambdaweb): CloudFormation types for Lambda Web Functions

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 in the registry schema, 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. Fn::GetAtt on RegionalEndpoints is recorded as a gap.

Part of #5699

* fix(lambdaweb): compare a revision against the function's default log group

revisionMatches filled a request without a log group with the existing
revision's log group, so a template that dropped a custom log group kept
the old revision. The default is the function's log group, as when a
revision is created. replaceTags returns the updated function.

* fix(cloudformation): put a Lambda Web function or endpoint back after a failed stack update

A function's tags and an endpoint's mutable configuration are changed in
place on update. The provisioner now snapshots them before the change and
restores them from rollbackUpdate, as the other in-place provisioners do.
The function attributes after a tag update come from the updated
function, so UpdatedAt moves with the tag change.

* test(cloudformation): roll a Lambda Web stack update back after a failed revision

A revision that fails to create after the endpoint moved to a replaced
revision rolls the stack back. The endpoint returns to the kept revision
and the replacement is deleted. The doc page says that a CloudFormation
endpoint is always Disabled with RevisionWeights, since the schema has no
AutoDeploymentMode, and that a failed update puts in-place changes back.

* fix(cloudformation): refuse AutoDeploymentMode on a Lambda Web endpoint

The registry schema has no AutoDeploymentMode property and AWS fails a
template that sets it at validation. An endpoint from CloudFormation is
always Disabled and routes by RevisionWeights. Floci passed the property
through to the service, which accepted LatestRevision.

* refactor(lambdaweb): share the create and tag steps between the API and CloudFormation paths

createFunction and createFunctionShell both check the name and refuse a
duplicate under the function's lock. tagResource and replaceTags both
check the tags, lock, write, stamp and persist. Each pair now calls one
private helper, so the two paths cannot drift.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-15 19:02:50 -04:00
1 parent 01cc020419
commit 0492fc9842
13 files changed
+1223 -21

No files matched your search

@@ -112,6 +112,14 @@ public final class CfnRollback {
*/
public static final String REST_API_UPDATE_SNAPSHOT_ATTR = "__FlociRestApiUpdateSnapshot";
/**
* Holds the tags a web function or the mutable configuration a web function endpoint carried
* before the in-place update in flight changed it, so a failed stack update can put it back.
* Written by {@code LambdaWebCfnProvisioner} before its update call and spent by its
* {@code rollbackUpdate}.
*/
public static final String LAMBDA_WEB_UPDATE_SNAPSHOT_ATTR = "__FlociLambdaWebUpdateSnapshot";
/**
* Holds the function ARN, status, caching flag, token settings and tags an IoT authorizer
* carried before an in-place update changed them, so a failed stack update can put them back.
@@ -0,0 +1,350 @@
package io.github.hectorvent.floci.services.cloudformation.provisioners;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
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.LambdaWebService;
import io.github.hectorvent.floci.services.lambdaweb.model.WebFunction;
import io.github.hectorvent.floci.services.lambdaweb.model.WebFunctionEndpoint;
import io.github.hectorvent.floci.services.lambdaweb.model.WebFunctionRevision;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import java.util.regex.Pattern;
/**
* CloudFormation provisioning for {@code AWS::Lambda::WebFunction}, {@code WebFunctionRevision} and
* {@code WebFunctionEndpoint}. Each physical id is the resource's ARN, the schemas' primaryIdentifier.
* Every property of a revision is createOnly. A function's createOnly property is its name, an
* endpoint's are its function, name, type and regions.
*/
@ApplicationScoped
public class LambdaWebCfnProvisioner implements CfnResourceProvisioner {
static final String FUNCTION = "AWS::Lambda::WebFunction";
static final String REVISION = "AWS::Lambda::WebFunctionRevision";
static final String ENDPOINT = "AWS::Lambda::WebFunctionEndpoint";
private static final Logger LOG = Logger.getLogger(LambdaWebCfnProvisioner.class);
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final Set<String> ENDPOINT_CREATE_ONLY = Set.of("FunctionName", "EndpointName", "EndpointType", "Regions");
/** Integer properties. A parameter or mapping value arrives as text, which CloudFormation coerces. */
private static final Set<String> INTEGER_PROPERTIES =
Set.of("TimeoutSeconds", "MaxConcurrencyPerEnvironment", "Weight", "MaxEnvironments", "RateLimit");
private static final Pattern INTEGER_TEXT = Pattern.compile("-?[0-9]{1,10}");
private final LambdaWebService service;
@Inject
public LambdaWebCfnProvisioner(LambdaWebService service) {
this.service = service;
}
@Override
public Set<String> resourceTypes() {
return Set.of(FUNCTION, REVISION, ENDPOINT);
}
@Override
public void provision(StackResource r, JsonNode props, ProvisionContext ctx) {
switch (r.getResourceType()) {
case FUNCTION -> provisionFunction(r, props, ctx);
case REVISION -> provisionRevision(r, props, ctx);
case ENDPOINT -> provisionEndpoint(r, props, ctx);
default -> throw new IllegalStateException("LambdaWebCfnProvisioner cannot handle " + r.getResourceType());
}
}
/** A revision an endpoint still routes to keeps its ConflictException, so the stack reports it. */
@Override
public void delete(String resourceType, String physicalId, String region) {
switch (resourceType) {
case FUNCTION -> CfnDeletes.safeDelete("web function", physicalId,
() -> service.deleteFunction(region, physicalId), "ResourceNotFoundException");
case REVISION -> CfnDeletes.safeDelete("web function revision", physicalId,
() -> service.deleteRevision(region, functionArnOf(physicalId), physicalId), "ResourceNotFoundException");
case ENDPOINT -> CfnDeletes.safeDelete("web function endpoint", physicalId,
() -> service.deleteEndpoint(region, functionArnOf(physicalId), physicalId), "ResourceNotFoundException");
default -> { }
}
}
@Override
public boolean hasReplacementUpdate(StackResource resource) {
return ReplacementCleanup.hasReplacement(resource);
}
@Override
public String updateCleanupPhysicalId(StackResource resource) {
return ReplacementCleanup.cleanupPhysicalId(resource);
}
@Override
public UpdateCleanupResult completeUpdate(StackResource resource) {
return ReplacementCleanup.complete(resource, this::delete);
}
@Override
public void clearUpdate(StackResource resource) {
resource.getAttributes().remove(CfnRollback.LAMBDA_WEB_UPDATE_SNAPSHOT_ATTR);
ReplacementCleanup.clear(resource);
}
/** An in-place change is undone from the snapshot taken before it; the snapshot stays until that succeeds. */
@Override
public boolean rollbackUpdate(StackResource resource) {
if (ReplacementCleanup.rollback(resource, this::delete)) {
return true;
}
String raw = resource.getAttributes().get(CfnRollback.LAMBDA_WEB_UPDATE_SNAPSHOT_ATTR);
if (raw == null) {
return false;
}
JsonNode snapshot;
try {
snapshot = MAPPER.readTree(raw);
} catch (JsonProcessingException e) {
LOG.errorv("Could not parse the Lambda Web update snapshot of {0}: {1}", resource.getLogicalId(), e.getMessage());
return false;
}
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"));
} else {
service.replaceTags(region, functionArn,
MAPPER.convertValue(snapshot.get("tags"), new TypeReference<Map<String, String>>() {}));
}
resource.getAttributes().remove(CfnRollback.LAMBDA_WEB_UPDATE_SNAPSHOT_ATTR);
return true;
}
private void provisionFunction(StackResource r, JsonNode props, ProvisionContext ctx) {
String name = require(props, "FunctionName", r, ctx);
Map<String, String> tags = ctx.resolveTags(props, "Tags");
Map<String, String> attributesBefore = new HashMap<>(r.getAttributes());
WebFunction fn = ctx.isUpdate() ? find(() -> service.getFunction(ctx.region(), name)) : null;
if (fn != null && ctx.reusesPriorEntity(fn.functionArn)) {
if (!tags.equals(fn.tags)) {
r.getAttributes().put(CfnRollback.LAMBDA_WEB_UPDATE_SNAPSHOT_ATTR, tagSnapshot(ctx.region(), fn).toString());
fn = service.replaceTags(ctx.region(), name, tags);
}
} else {
fn = service.createFunctionShell(ctx.region(), name, tags);
}
r.setPhysicalId(fn.functionArn);
ReplacementCleanup.record(r, ctx, attributesBefore);
r.getAttributes().put("FunctionArn", fn.functionArn);
r.getAttributes().put("State", "Active");
r.getAttributes().put("StateReason", "The function is active.");
r.getAttributes().put("CreatedAt", LambdaWebService.formatTimestamp(fn.createdAt));
r.getAttributes().put("UpdatedAt", LambdaWebService.formatTimestamp(fn.updatedAt));
}
private void provisionRevision(StackResource r, JsonNode props, ProvisionContext ctx) {
String functionName = require(props, "FunctionName", r, ctx);
JsonNode request = toCamelCase(ctx.engine().resolveNodeOmittingNoValue(props), Set.of("FunctionName"));
Map<String, String> attributesBefore = new HashMap<>(r.getAttributes());
WebFunctionRevision revision = null;
if (reusablePrior(ctx, attributesBefore)) {
WebFunction fn = find(() -> service.getFunction(ctx.region(), functionName));
String prior = ctx.priorPhysicalId();
WebFunctionRevision existing = find(() -> service.getRevision(ctx.region(), functionArnOf(prior), prior));
if (fn != null && existing != null && existing.functionArn.equals(fn.functionArn)
&& service.revisionMatches(existing, request)) {
revision = existing;
}
}
if (revision == null) {
revision = service.createRevision(ctx.region(), functionName, request);
}
r.setPhysicalId(revision.revisionArn);
ReplacementCleanup.record(r, ctx, attributesBefore);
r.getAttributes().put("FunctionArn", revision.functionArn);
r.getAttributes().put("RevisionArn", revision.revisionArn);
r.getAttributes().put("RevisionId", revision.revisionId);
r.getAttributes().put("State", "Active");
r.getAttributes().put("StateReason", "The revision is active.");
r.getAttributes().put("CreatedAt", LambdaWebService.formatTimestamp(revision.createdAt));
}
private void provisionEndpoint(StackResource r, JsonNode props, ProvisionContext ctx) {
String functionName = require(props, "FunctionName", r, ctx);
JsonNode resolved = ctx.engine().resolveNodeOmittingNoValue(props);
if (resolved.has("AutoDeploymentMode")) {
// Not in the registry schema: a CloudFormation endpoint routes by RevisionWeights only.
throw new IllegalArgumentException(r.getResourceType() + " has no AutoDeploymentMode property ("
+ r.getLogicalId() + ")");
}
Map<String, String> attributesBefore = new HashMap<>(r.getAttributes());
WebFunctionEndpoint endpoint = null;
if (reusablePrior(ctx, attributesBefore)) {
WebFunction fn = find(() -> service.getFunction(ctx.region(), functionName));
String prior = ctx.priorPhysicalId();
WebFunctionEndpoint existing = find(() -> service.getEndpoint(ctx.region(), functionArnOf(prior), prior));
if (fn != null && existing != null && existing.functionArn.equals(fn.functionArn)) {
if (sameIdentity(existing, resolved, ctx.region())) {
r.getAttributes().put(CfnRollback.LAMBDA_WEB_UPDATE_SNAPSHOT_ATTR,
endpointSnapshot(ctx.region(), existing).toString());
endpoint = service.updateEndpoint(ctx.region(), functionName, existing.endpointName,
endpointPatch(resolved, ctx)).after();
} else if (existing.endpointName.equals(resolved.path("EndpointName").asText())) {
throw CfnExceptions.customNamedReplacement(existing.endpointName);
}
}
}
if (endpoint == null) {
endpoint = service.createEndpoint(ctx.region(), functionName, toCamelCase(resolved, Set.of("FunctionName")));
}
r.setPhysicalId(endpoint.endpointArn);
ReplacementCleanup.record(r, ctx, attributesBefore);
r.getAttributes().put("FunctionArn", endpoint.functionArn);
r.getAttributes().put("EndpointArn", endpoint.endpointArn);
r.getAttributes().put("DomainName", endpoint.domainName);
r.getAttributes().put("State", "Active");
r.getAttributes().put("StateReason", "The endpoint is active and invokable.");
if (endpoint.updateStatus != null) {
r.getAttributes().put("UpdateStatus", endpoint.updateStatus);
r.getAttributes().put("UpdateStatusReason", "The endpoint is updated.");
} else {
r.getAttributes().remove("UpdateStatus");
r.getAttributes().remove("UpdateStatusReason");
}
r.getAttributes().put("CreatedAt", LambdaWebService.formatTimestamp(endpoint.createdAt));
r.getAttributes().put("UpdatedAt", LambdaWebService.formatTimestamp(endpoint.updatedAt));
}
/** The in-place update. A property the previous template declared and this one dropped is cleared. */
private static ObjectNode endpointPatch(JsonNode resolved, ProvisionContext ctx) {
ObjectNode patch = (ObjectNode) toCamelCase(resolved, ENDPOINT_CREATE_ONLY);
if (!patch.has("scalingConfig") && ctx.previouslyDeclared("ScalingConfig")) {
patch.putObject("scalingConfig");
}
if (!patch.has("throttleConfig") && ctx.previouslyDeclared("ThrottleConfig")) {
patch.putObject("throttleConfig");
}
if (!patch.has("description") && ctx.previouslyDeclared("Description")) {
patch.put("description", "");
}
return patch;
}
private static ObjectNode tagSnapshot(String region, WebFunction fn) {
ObjectNode snapshot = MAPPER.createObjectNode().put("type", "function").put("region", region)
.put("functionArn", fn.functionArn);
ObjectNode tags = snapshot.putObject("tags");
fn.tags.forEach(tags::put);
return snapshot;
}
/** The endpoint's mutable configuration in the shape {@code UpdateWebFunctionEndpoint} takes. */
private static ObjectNode endpointSnapshot(String region, WebFunctionEndpoint endpoint) {
ObjectNode snapshot = MAPPER.createObjectNode().put("type", "endpoint").put("region", region)
.put("functionArn", endpoint.functionArn).put("endpointName", endpoint.endpointName);
ObjectNode patch = snapshot.putObject("patch");
patch.put("authType", endpoint.authType);
patch.put("description", endpoint.description == null ? "" : endpoint.description);
patch.put("autoDeploymentMode", endpoint.autoDeploymentMode);
if (!"LatestRevision".equals(endpoint.autoDeploymentMode)) {
ArrayNode weights = patch.putArray("revisionWeights");
for (WebFunctionEndpoint.RevisionWeight weight : endpoint.revisionWeights) {
weights.addObject().put("revisionId", weight.revisionId).put("weight", weight.weight);
}
}
ObjectNode scaling = patch.putObject("scalingConfig");
if (endpoint.scalingConfig != null && endpoint.scalingConfig.maxEnvironments != null) {
scaling.put("maxEnvironments", endpoint.scalingConfig.maxEnvironments);
}
ObjectNode throttle = patch.putObject("throttleConfig");
if (endpoint.throttleConfig != null && endpoint.throttleConfig.rateLimit != null) {
throttle.put("rateLimit", endpoint.throttleConfig.rateLimit);
}
return snapshot;
}
private static boolean reusablePrior(ProvisionContext ctx, Map<String, String> attributesBefore) {
return ctx.isUpdate() && !CfnResourceDispatcher.isStub(ctx.priorPhysicalId(), attributesBefore);
}
private static boolean sameIdentity(WebFunctionEndpoint existing, JsonNode props, String homeRegion) {
if (!existing.endpointName.equals(props.path("EndpointName").asText())
|| !existing.endpointType.equals(props.path("EndpointType").asText())) {
return false;
}
Set<String> regions = new LinkedHashSet<>();
regions.add(homeRegion);
props.path("Regions").forEach(region -> regions.add(region.asText()));
return regions.equals(new LinkedHashSet<>(existing.regions));
}
private static <T> T find(Supplier<T> lookup) {
try {
return lookup.get();
} catch (AwsException e) {
if (!"ResourceNotFoundException".equals(e.getErrorCode())) {
throw e;
}
LOG.debugv("No prior web function entity to reuse: {0}", e.getMessage());
return null;
}
}
private static String require(JsonNode props, String name, StackResource r, ProvisionContext ctx) {
String value = ctx.resolveOptional(props, name);
if (value == null || value.isBlank()) {
throw new IllegalArgumentException(r.getResourceType() + " requires " + name + " (" + r.getLogicalId() + ")");
}
return value;
}
private static String functionArnOf(String childArn) {
int child = childArn.indexOf("/revision/");
if (child < 0) {
child = childArn.indexOf("/endpoint/");
}
return child < 0 ? childArn : childArn.substring(0, child);
}
/** The keys of {@code EnvironmentVariables} are the user's own and stay as written. */
private static JsonNode toCamelCase(JsonNode node, Set<String> skip) {
if (node == null || !node.isObject()) {
return MAPPER.createObjectNode();
}
ObjectNode out = MAPPER.createObjectNode();
node.fields().forEachRemaining(entry -> {
if (skip.contains(entry.getKey())) {
return;
}
String key = Character.toLowerCase(entry.getKey().charAt(0)) + entry.getKey().substring(1);
JsonNode value = entry.getValue();
if (INTEGER_PROPERTIES.contains(entry.getKey()) && value.isTextual()
&& INTEGER_TEXT.matcher(value.textValue()).matches()) {
value = MAPPER.getNodeFactory().numberNode(Long.parseLong(value.textValue()));
}
out.set(key, "EnvironmentVariables".equals(entry.getKey()) ? value : lowerKeys(value));
});
return out;
}
private static JsonNode lowerKeys(JsonNode node) {
if (node.isObject()) {
return toCamelCase(node, Set.of());
}
if (node.isArray()) {
ArrayNode out = MAPPER.createArrayNode();
node.forEach(item -> out.add(lowerKeys(item)));
return out;
}
return node;
}
}
@@ -41,6 +41,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -191,9 +192,7 @@ public class LambdaWebService implements Resettable {
validateTagsShape(validation, "tags", tags);
validation.throwIfAny();
if (!FUNCTION_NAME.matcher(functionName).matches()) {
throw invalidFunctionName(functionName);
}
requireFunctionName(functionName);
if (revisionConfig == null || endpointConfig == null) {
throw new AwsException("ValidationException",
"The revisionConfig and endpointConfig must be specified.", 400);
@@ -202,19 +201,44 @@ public class LambdaWebService implements Resettable {
validateRevisionRules(revisionConfig);
String accountId = regionResolver.getAccountId();
WebFunctionEndpoint endpoint = draftEndpoint(region, accountId, functionName, endpointConfig, false);
String arn = functionArn(region, accountId, functionName);
synchronized (lockFor(region, functionName)) {
if (functions.get(key(region, functionName)).isPresent()) {
throw new AwsException("ConflictException", "The function " + arn + " already exists.", 409);
}
WebFunction fn = newFunction(region, accountId, functionName, tags == null ? Map.of() : tags);
return storeNewFunction(region, functionName, tags, fn -> {
WebFunctionRevision revision = buildRevision(fn, revisionConfig);
attachEndpoint(region, fn, endpoint, revision);
fn.revisions.put(revision.revisionId, revision);
fn.endpoints.put(endpoint.endpointName, endpoint);
functions.put(key(region, functionName), fn);
LOG.infov("Created web function {0} with revision {1} and endpoint {2}",
functionName, revision.revisionId, endpoint.endpointName);
});
}
/** A function with no revision and no endpoint, for AWS::Lambda::WebFunction. */
public WebFunction createFunctionShell(String region, String functionName, Map<String, String> tags) {
requireFunctionName(functionName);
LambdaWebValidation validation = new LambdaWebValidation();
validateTagsShape(validation, "tags", tags);
validation.throwIfAny();
requireValidTags(tags);
return storeNewFunction(region, functionName, tags, fn -> { });
}
private static void requireFunctionName(String functionName) {
if (functionName == null || !FUNCTION_NAME.matcher(functionName).matches()) {
throw invalidFunctionName(functionName);
}
}
/** Stores a new function under its lock, refusing a name the region already has. */
private WebFunction storeNewFunction(String region, String functionName, Map<String, String> tags,
Consumer<WebFunction> populate) {
String accountId = regionResolver.getAccountId();
synchronized (lockFor(region, functionName)) {
if (functions.get(key(region, functionName)).isPresent()) {
throw new AwsException("ConflictException",
"The function " + functionArn(region, accountId, functionName) + " already exists.", 409);
}
WebFunction fn = newFunction(region, accountId, functionName, tags == null ? Map.of() : tags);
populate.accept(fn);
functions.put(key(region, functionName), fn);
return copy(fn, WebFunction.class);
}
}
@@ -337,6 +361,31 @@ public class LambdaWebService implements Resettable {
}
}
/** Whether a revision already carries the configuration a request describes. */
public boolean revisionMatches(WebFunctionRevision existing, JsonNode request) {
WebFunctionRevision desired = new WebFunctionRevision();
desired.description = LambdaWebJson.text(request, "description");
desired.kmsKeyArn = LambdaWebJson.text(request, "kmsKeyArn");
desired.buildConfig = buildConfigOf(LambdaWebJson.structure(request, "buildConfig"));
String functionName = existing.functionArn.substring(existing.functionArn.lastIndexOf('/') + 1);
desired.serviceConfig = serviceConfigOf(LambdaWebJson.structure(request, "serviceConfig"),
defaultLogGroup(functionName));
return objectMapper.valueToTree(configOnly(existing)).equals(objectMapper.valueToTree(configOnly(desired)));
}
private static String defaultLogGroup(String functionName) {
return "/aws/lambda/web/" + functionName;
}
private static WebFunctionRevision configOnly(WebFunctionRevision revision) {
WebFunctionRevision copy = new WebFunctionRevision();
copy.description = revision.description;
copy.kmsKeyArn = revision.kmsKeyArn;
copy.buildConfig = revision.buildConfig;
copy.serviceConfig = revision.serviceConfig;
return copy;
}
private static WebFunctionRevision revision(WebFunction fn, String revisionId) {
WebFunctionRevision revision = fn.revisions.get(revisionId);
if (revision == null) {
@@ -372,7 +421,7 @@ public class LambdaWebService implements Resettable {
"The runtime " + revision.buildConfig.runtime + " is invalid.", 400);
}
revision.serviceConfig = serviceConfigOf(LambdaWebJson.structure(request, "serviceConfig"),
"/aws/lambda/web/" + fn.functionName);
defaultLogGroup(fn.functionName));
requireCodeObject(revision.buildConfig);
revision.description = LambdaWebJson.text(request, "description");
revision.kmsKeyArn = LambdaWebJson.text(request, "kmsKeyArn");
@@ -872,14 +921,7 @@ public class LambdaWebService implements Resettable {
validation.pattern("resource", resourceArn, RESOURCE_ARN).required("tags", tags);
validateTagsShape(validation, "tags", tags);
validation.throwIfAny();
requireValidTags(tags);
String functionName = resolveFunctionName(region, resourceArn, "TagResource");
synchronized (lockFor(region, functionName)) {
WebFunction fn = function(region, functionName);
fn.tags.putAll(tags);
fn.updatedAt = now();
persist(region, fn);
}
writeTags(region, resourceArn, tags, fn -> fn.tags.putAll(tags));
}
public void untagResource(String region, String resourceArn, List<String> tagKeys) {
@@ -900,6 +942,27 @@ public class LambdaWebService implements Resettable {
}
}
/** Sets the stored tags to exactly {@code desired}, for AWS::Lambda::WebFunction. */
public WebFunction replaceTags(String region, String functionNameOrArn, Map<String, String> desired) {
LambdaWebValidation validation = new LambdaWebValidation();
validateTagsShape(validation, "tags", desired);
validation.throwIfAny();
return writeTags(region, functionNameOrArn, desired, fn -> fn.tags = new LinkedHashMap<>(desired));
}
private WebFunction writeTags(String region, String functionNameOrArn, Map<String, String> tags,
Consumer<WebFunction> write) {
requireValidTags(tags);
String functionName = resolveFunctionName(region, functionNameOrArn, "TagResource");
synchronized (lockFor(region, functionName)) {
WebFunction fn = function(region, functionName);
write.accept(fn);
fn.updatedAt = now();
persist(region, fn);
return copy(fn, WebFunction.class);
}
}
private static void validateTagsShape(LambdaWebValidation v, String path, Map<String, String> tags) {
if (tags == null || tags.isEmpty()) {
return;