aws/endpoints
Smithy endpoint rule set evaluator.
Implements the runtime side of the Smithy rules engine: parses a
endpoint-rule-set.json document, then walks it against a set of
parameter values and produces a concrete endpoint URL.
Supported features:
- Rule types:
endpoint,error,tree - Parameters:
String,Boolean, withdefaultandrequired - Templates:
{Name}and{Var#field}(and nested{Var#a#b}) - Built-in functions:
isSet,not,booleanEquals,stringEquals,getAttr,substring,uriEncode,parseURL,isValidHostLabel,aws.partition,aws.parseArn,aws.isVirtualHostableS3Bucket - Common partition data hardcoded (
aws,aws-cn,aws-us-gov). For a richer table, vendorpartitions.jsonand replacepartition_for/1.
Not implemented (rare; flagged at evaluation time as Unsupported):
StringArrayparameter type (used by a few new services)
Codegen at milestone 7 will use this evaluator at compile time to emit per-service endpoint resolvers; the runtime fallback path here keeps hand-written services working before any code is generated.
Types
pub type Condition {
Condition(expr: Expr, assign: option.Option(String))
}
Constructors
-
Condition(expr: Expr, assign: option.Option(String))
pub type Expr {
Ref(name: String)
TemplateExpr(parts: List(TemplatePart))
BoolLit(value: Bool)
IntLit(value: Int)
FnCall(name: String, args: List(Expr))
}
Constructors
-
Ref(name: String)Reference to a parameter or assigned variable.
-
TemplateExpr(parts: List(TemplatePart))String literal that may contain
{Name}and{Var#field}interpolations. -
BoolLit(value: Bool) -
IntLit(value: Int)Integer literal —
substring(input, 0, 3, false)and similar. -
FnCall(name: String, args: List(Expr))Builtin function call. The function name is the raw “fn” value (e.g.
"isSet","aws.partition").
pub type Parameter {
Parameter(
type_: ParamType,
required: Bool,
default: option.Option(Value),
builtin: option.Option(String),
)
}
Constructors
-
Parameter( type_: ParamType, required: Bool, default: option.Option(Value), builtin: option.Option(String), )
pub type ResolveError {
RuleError(message: String)
NoMatch
InvalidRuleSet(reason: String)
Unsupported(reason: String)
MissingParameter(name: String)
RequiredParameterMissing(name: String)
}
Constructors
-
RuleError(message: String)A rule’s
errorbranch fired with this message. -
NoMatchNo rule matched (the rule set is supposed to always end in either an endpoint or an error rule, so this normally indicates a bad rule set).
-
InvalidRuleSet(reason: String)JSON could not be parsed into a
RuleSet. -
Unsupported(reason: String)Evaluation tripped over an unimplemented function or a parameter type the evaluator doesn’t support yet.
-
MissingParameter(name: String)A parameter referenced by a rule wasn’t supplied and has no default.
-
RequiredParameterMissing(name: String)A required parameter is unset.
pub type Rule {
EndpointRule(
conditions: List(Condition),
endpoint: EndpointSpec,
)
ErrorRule(conditions: List(Condition), message: Expr)
TreeRule(conditions: List(Condition), rules: List(Rule))
}
Constructors
-
EndpointRule(conditions: List(Condition), endpoint: EndpointSpec) -
-
pub type TemplatePart {
Static(text: String)
Interp(path: List(String))
}
Constructors
-
Static(text: String) -
Interp(path: List(String))
Runtime values that flow through evaluation: literals plus the record
shape that aws.partition returns plus the list shape used for
stringArray parameters and the resourceId field of a parsed ARN.
pub type Value {
StringVal(String)
BoolVal(Bool)
RecordVal(dict.Dict(String, Value))
ListVal(List(Value))
EmptyVal
}
Constructors
-
StringVal(String) -
BoolVal(Bool) -
-
ListVal(List(Value)) -
EmptyVal
Values
pub fn params_from(
strings strings: List(#(String, String)),
bools bools: List(#(String, Bool)),
) -> dict.Dict(String, Value)
Convenience constructor: build a Params map from string and boolean
pairs. The most common shape (Region + UseFips + UseDualStack).
pub fn parse_rule_set(
json_text: String,
) -> Result(RuleSet, ResolveError)
Parse a rule set JSON document (as a Gleam string) into the internal AST.
The result is reusable across many resolve calls with different params.