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:

Not implemented (rare; flagged at evaluation time as Unsupported):

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

pub type Endpoint {
  Endpoint(url: String, headers: dict.Dict(String, List(String)))
}

Constructors

  • Endpoint(url: String, headers: dict.Dict(String, List(String)))
pub type EndpointSpec {
  EndpointSpec(url: Expr, headers: dict.Dict(String, List(Expr)))
}

Constructors

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 ParamType {
  StringType
  BooleanType
}

Constructors

  • StringType
  • BooleanType
pub type Parameter {
  Parameter(
    type_: ParamType,
    required: Bool,
    default: option.Option(Value),
    builtin: option.Option(String),
  )
}

Constructors

Parameter values supplied to evaluation. Keys are parameter names.

pub type Params =
  dict.Dict(String, Value)
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 error branch fired with this message.

  • NoMatch

    No 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

pub type RuleSet {
  RuleSet(
    parameters: dict.Dict(String, Parameter),
    rules: List(Rule),
  )
}

Constructors

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)
  • RecordVal(dict.Dict(String, Value))
  • 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.

pub fn resolve(
  rule_set: RuleSet,
  params: dict.Dict(String, Value),
) -> Result(Endpoint, ResolveError)

Walk the rule set with the given parameters. Returns the first matching endpoint, the first matching error rule (surfaced as RuleError), or NoMatch if every rule’s conditions failed.

Search Document