AWS specific components for managing endpoints in Smithy
The Smithy traits provide annotation capabilities for describing AWS endpoint behavior and configuration in Smithy models. These traits enable declarative specification of endpoint patterns, special cases, and AWS-specific endpoint requirements.
/**
* A trait that indicates that a service has handwritten endpoint rules.
* Services marked with this trait have handwritten endpoint rules that extend or replace
* their standard generated endpoint rules through an external mechanism.
*/
public final class RuleBasedEndpointsTrait extends AnnotationTrait {
/** Trait shape ID */
public static final ShapeId ID = ShapeId.from("aws.endpoints#rulesBasedEndpoints");
/**
* Creates a new RuleBasedEndpointsTrait with empty configuration
*/
public RuleBasedEndpointsTrait();
/**
* Creates a new RuleBasedEndpointsTrait from object node
* @param node Configuration object node
*/
public RuleBasedEndpointsTrait(ObjectNode node);
/**
* Trait provider for service registration
*/
public static final class Provider extends AnnotationTrait.Provider<RuleBasedEndpointsTrait> {
public Provider();
}
}/**
* A trait that indicates a service uses standard regional endpoint patterns.
*/
public final class StandardRegionalEndpointsTrait extends AnnotationTrait {
/** Trait shape ID */
public static final ShapeId ID = ShapeId.from("aws.endpoints#standardRegionalEndpoints");
/**
* Creates a new StandardRegionalEndpointsTrait with empty configuration
*/
public StandardRegionalEndpointsTrait();
/**
* Creates a new StandardRegionalEndpointsTrait from object node
* @param node Configuration object node
*/
public StandardRegionalEndpointsTrait(ObjectNode node);
/**
* Trait provider for service registration
*/
public static final class Provider extends AnnotationTrait.Provider<StandardRegionalEndpointsTrait> {
public Provider();
}
}/**
* A trait that indicates a service uses standard partitional endpoint patterns.
*/
public final class StandardPartitionalEndpointsTrait extends AnnotationTrait {
/** Trait shape ID */
public static final ShapeId ID = ShapeId.from("aws.endpoints#standardPartitionalEndpoints");
/**
* Creates a new StandardPartitionalEndpointsTrait with empty configuration
*/
public StandardPartitionalEndpointsTrait();
/**
* Creates a new StandardPartitionalEndpointsTrait from object node
* @param node Configuration object node
*/
public StandardPartitionalEndpointsTrait(ObjectNode node);
/**
* Trait provider for service registration
*/
public static final class Provider extends AnnotationTrait.Provider<StandardPartitionalEndpointsTrait> {
public Provider();
}
}/**
* A trait that indicates that a service only supports dual-stack endpoints.
*/
public final class DualStackOnlyEndpointsTrait extends AnnotationTrait {
/** Trait shape ID */
public static final ShapeId ID = ShapeId.from("aws.endpoints#dualStackOnlyEndpoints");
/**
* Creates a new DualStackOnlyEndpointsTrait with empty configuration
*/
public DualStackOnlyEndpointsTrait();
/**
* Creates a new DualStackOnlyEndpointsTrait from object node
* @param node Configuration object node
*/
public DualStackOnlyEndpointsTrait(ObjectNode node);
/**
* Trait provider for service registration
*/
public static final class Provider extends AnnotationTrait.Provider<DualStackOnlyEndpointsTrait> {
public Provider();
}
}/**
* A trait for modifying endpoint behavior with patterns and special cases.
*/
public final class EndpointModifierTrait extends AbstractTrait {
/** Trait shape ID */
public static final ShapeId ID = ShapeId.from("aws.endpoints#endpointModifier");
/**
* Creates a new EndpointModifierTrait from builder
* @param builder Trait builder
*/
public EndpointModifierTrait(Builder builder);
/**
* Gets the endpoint pattern type
* @return Endpoint pattern type
*/
public EndpointPatternType getPattern();
/**
* Gets the special case configurations
* @return List of special cases
*/
public List<PartitionSpecialCase> getSpecialCases();
/**
* Creates a builder for this trait
* @return New builder instance
*/
public static Builder builder();
/**
* Converts this trait to a builder
* @return Builder with current trait values
*/
public Builder toBuilder();
/**
* Builder for EndpointModifierTrait
*/
public static final class Builder extends AbstractTraitBuilder<EndpointModifierTrait, Builder> {
/**
* Sets the endpoint pattern type
* @param pattern Endpoint pattern type
* @return This builder
*/
public Builder pattern(EndpointPatternType pattern);
/**
* Sets the special cases
* @param specialCases List of special cases
* @return This builder
*/
public Builder specialCases(List<PartitionSpecialCase> specialCases);
/**
* Adds a special case
* @param specialCase Special case to add
* @return This builder
*/
public Builder addSpecialCase(PartitionSpecialCase specialCase);
/**
* Builds the trait
* @return EndpointModifierTrait instance
*/
public EndpointModifierTrait build();
}
/**
* Trait provider for service registration
*/
public static final class Provider extends AbstractTrait.Provider {
public Provider();
}
}An annotation trait that indicates a service has only dual stack endpoints and does not support IPv4-only endpoints.
/**
* An endpoints modifier trait that indicates a service has only dual stack endpoints,
* does not support IPV4 only endpoints, and should not have the useDualStackEndpoint endpoint parameter.
*/
public final class DualStackOnlyEndpointsTrait extends AnnotationTrait {
public static final ShapeId ID = ShapeId.from("aws.endpoints#dualStackOnlyEndpoints");
/**
* Creates a DualStackOnlyEndpointsTrait from a node
* @param node The object node
*/
public DualStackOnlyEndpointsTrait(ObjectNode node);
/**
* Creates a DualStackOnlyEndpointsTrait with default configuration
*/
public DualStackOnlyEndpointsTrait();
/**
* Trait provider for service registration
*/
public static final class Provider extends AnnotationTrait.Provider<DualStackOnlyEndpointsTrait> {
public Provider();
}
}A trait that indicates that a service is partitional and a single endpoint should resolve per partition.
/**
* An endpoints modifier trait that indicates that a service is partitional
* and a single endpoint should resolve per partition.
*/
public final class StandardPartitionalEndpointsTrait extends AbstractTrait
implements ToSmithyBuilder<StandardPartitionalEndpointsTrait> {
public static final ShapeId ID = ShapeId.from("aws.endpoints#standardPartitionalEndpoints");
/**
* Gets the map of partition string to a list of partition endpoint special cases
* @return Map of partition string to list of PartitionEndpointSpecialCase
*/
public Map<String, List<PartitionEndpointSpecialCase>> getPartitionEndpointSpecialCases();
/**
* Gets the endpoint pattern type defined in the trait
* @return EndpointPatternType
*/
public EndpointPatternType getEndpointPatternType();
/**
* Creates a builder for the trait
* @return Builder instance
*/
public static Builder builder();
/**
* Builder for StandardPartitionalEndpointsTrait
*/
public static final class Builder extends AbstractTraitBuilder<StandardPartitionalEndpointsTrait, Builder> {
/**
* Sets the partition endpoint special cases
* @param partitionEndpointSpecialCases Map of partition string to list of PartitionEndpointSpecialCase
* @return This builder
*/
public Builder partitionEndpointSpecialCases(
Map<String, List<PartitionEndpointSpecialCase>> partitionEndpointSpecialCases);
/**
* Sets partition endpoint special cases for a specific partition
* @param partition The partition name
* @param partitionEndpointSpecialCases List of PartitionEndpointSpecialCase
* @return This builder
*/
public Builder putPartitionEndpointSpecialCase(
String partition,
List<PartitionEndpointSpecialCase> partitionEndpointSpecialCases);
/**
* Sets the endpoint pattern type
* @param endpointPatternType The endpoint pattern type
* @return This builder
*/
public Builder endpointPatternType(EndpointPatternType endpointPatternType);
/**
* Builds the trait
* @return StandardPartitionalEndpointsTrait instance
*/
public StandardPartitionalEndpointsTrait build();
}
/**
* Trait provider for service registration
*/
public static final class Provider extends AbstractTrait.Provider {
public Provider();
}
}/**
* Enum for endpoint pattern types
*/
public enum EndpointPatternType {
/** Regional endpoint pattern */
REGIONAL,
/** Partitional endpoint pattern */
PARTITIONAL,
/** Global endpoint pattern */
GLOBAL;
/**
* Gets the enum value from string
* @param value String representation
* @return EndpointPatternType value
*/
public static EndpointPatternType fromString(String value);
/**
* Gets the string representation
* @return String value
*/
public String toString();
}/**
* Special case configuration for partitions
*/
public final class PartitionSpecialCase {
/**
* Gets the partition name this special case applies to
* @return Partition name
*/
public String getPartition();
/**
* Gets the endpoint special cases for this partition
* @return List of partition endpoint special cases
*/
public List<PartitionEndpointSpecialCase> getEndpoints();
/**
* Creates a builder for PartitionSpecialCase
* @return New builder instance
*/
public static Builder builder();
}
/**
* Special case configuration for specific regions
*/
public final class RegionSpecialCase {
/**
* Gets the region this special case applies to
* @return Region name
*/
public String getRegion();
/**
* Gets the endpoint override for this region
* @return Endpoint override configuration
*/
public String getEndpoint();
/**
* Creates a builder for RegionSpecialCase
* @return New builder instance
*/
public static Builder builder();
}
/**
* Special case configuration for partition endpoints
*/
public final class PartitionEndpointSpecialCase {
/**
* Gets the endpoint template
* @return Endpoint template string
*/
public String getEndpoint();
/**
* Gets whether dual-stack is supported
* @return true if dual-stack is supported
*/
public boolean isDualStack();
/**
* Gets whether FIPS is supported
* @return true if FIPS is supported
*/
public boolean isFips();
/**
* Creates a builder for PartitionEndpointSpecialCase
* @return New builder instance
*/
public static Builder builder();
}/**
* Index for accessing endpoint modifier traits across models
*/
public final class EndpointModifierIndex implements KnowledgeIndex {
/**
* Creates an index from a model
* @param model Smithy model to index
* @return EndpointModifierIndex instance
*/
public static EndpointModifierIndex of(Model model);
/**
* Gets the endpoint modifier trait for a shape
* @param shapeId Shape to get modifier for
* @return Optional containing the modifier trait, or empty if not present
*/
public Optional<EndpointModifierTrait> getEndpointModifier(ToShapeId shapeId);
/**
* Gets all shapes with endpoint modifier traits
* @return Map of shape IDs to their endpoint modifier traits
*/
public Map<ShapeId, EndpointModifierTrait> getAllEndpointModifiers();
}Usage Examples:
import software.amazon.smithy.rulesengine.aws.traits.*;
import software.amazon.smithy.model.shapes.ServiceShape;
// Apply rule-based endpoints trait to a service
ServiceShape service = ServiceShape.builder()
.id("com.example#MyService")
.addTrait(new RuleBasedEndpointsTrait())
.build();
// Apply standard regional endpoints trait
ServiceShape regionalService = ServiceShape.builder()
.id("com.example#RegionalService")
.addTrait(new StandardRegionalEndpointsTrait())
.build();
// Apply dual-stack only trait
ServiceShape dualStackService = ServiceShape.builder()
.id("com.example#DualStackService")
.addTrait(new DualStackOnlyEndpointsTrait())
.build();
// Create endpoint modifier with special cases
EndpointModifierTrait endpointModifier = EndpointModifierTrait.builder()
.pattern(EndpointPatternType.REGIONAL)
.addSpecialCase(
PartitionSpecialCase.builder()
.partition("aws-us-gov")
.addEndpoint(
PartitionEndpointSpecialCase.builder()
.endpoint("service.{region}.amazonaws.com")
.fips(true)
.dualStack(false)
.build()
)
.build()
)
.build();
// Use endpoint modifier index
EndpointModifierIndex index = EndpointModifierIndex.of(model);
Optional<EndpointModifierTrait> modifier = index.getEndpointModifier(serviceId);Applied to service shapes to declare endpoint behavior:
@aws.endpoints#rulesBasedEndpoints
service MyCustomService {}
@aws.endpoints#standardRegionalEndpoints
service StandardService {}
@aws.endpoints#dualStackOnlyEndpoints
service IPv6OnlyService {}@aws.endpoints#endpointModifier(
pattern: "regional",
specialCases: [
{
partition: "aws-us-gov",
endpoints: [
{
endpoint: "service.{region}.amazonaws.com",
fips: true,
dualStack: false
}
]
}
]
)
service ConfigurableService {}All traits are automatically registered through the Java Service Provider Interface:
META-INF/services/software.amazon.smithy.model.traits.TraitServiceThe registration includes:
RuleBasedEndpointsTrait$ProviderStandardRegionalEndpointsTrait$ProviderStandardPartitionalEndpointsTrait$ProviderDualStackOnlyEndpointsTrait$ProviderEndpointModifierTrait$ProviderThese traits work with the Smithy rules engine to:
Install with Tessl CLI
npx tessl i tessl/maven-software-amazon-smithy--smithy-aws-endpoints