Documentation
¶
Overview ¶
Package awsquery provides parsers and encoders for the AWS query-protocol wire format used by EC2, Auto-Scaling, STS, and several other services.
The query protocol is a POST (or GET) with form-encoded parameters where lists are flattened with dotted indices:
Action=RunInstances&ImageId=ami-123&InstanceType=t2.micro &SecurityGroupId.1=sg-a&SecurityGroupId.2=sg-b &TagSpecification.1.ResourceType=instance &TagSpecification.1.Tag.1.Key=Name &TagSpecification.1.Tag.1.Value=my-box &Filter.1.Name=instance-state-name&Filter.1.Value.1=running
Responses are XML envelopes carrying a RequestId and a service-specific payload under a top-level <ActionResponse> element.
Index ¶
- Constants
- func CollectIndices(form url.Values, prefix string) []int
- func FlatTags(form url.Values, prefix string) map[string]string
- func ListStrings(form url.Values, prefix string) []string
- func WriteXMLError(w http.ResponseWriter, status int, code, message string)
- func WriteXMLResponse(w http.ResponseWriter, v any)
- type Error
- type ErrorResponse
- type Filter
- type TagSpec
Constants ¶
const Namespace = "http://ec2.amazonaws.com/doc/2016-11-15/"
Namespace is the XML namespace for AWS EC2 responses.
const RequestID = "00000000-0000-0000-0000-000000000000"
RequestID is the stub request id embedded in every response. Real AWS uses UUIDs; any well-formed value satisfies SDK clients.
Variables ¶
This section is empty.
Functions ¶
func CollectIndices ¶
CollectIndices returns the unique ascending N values for which any form key starts with "<prefix>.N" or "<prefix>.N.*". Exposed so sibling packages parsing deeply-nested AWS wire structures can reuse the same logic.
func FlatTags ¶
FlatTags parses the simpler Tag.N.Key / Tag.N.Value form used by APIs such as CreateTags on an existing resource. The prefix is typically "Tag".
func ListStrings ¶
ListStrings collects values of a flattened string list from form parameters. For prefix "SecurityGroupId" it returns values for keys "SecurityGroupId.1", "SecurityGroupId.2", ... in index order.
func WriteXMLError ¶
func WriteXMLError(w http.ResponseWriter, status int, code, message string)
WriteXMLError writes an AWS-style XML error response. The response shape is compatible with both the EC2 query SDK and the standard query SDKs (RDS, Redshift, Neptune, DocumentDB).
func WriteXMLResponse ¶
func WriteXMLResponse(w http.ResponseWriter, v any)
WriteXMLResponse marshals a pre-built response envelope to the client. The caller's struct is expected to carry an XMLName of "<Action>Response" and an xmlns attr (see examples in server/aws/ec2). This function only handles the HTTP preamble so every op has a uniform response path.
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
XMLName xml.Name `xml:"Response"`
Errors []Error `xml:"Errors>Error"`
Error Error `xml:"Error"`
RequestID string `xml:"RequestID"`
//nolint:revive,stylecheck,staticcheck // SDKs literally look for "RequestId", not "RequestID"; the second field is intentional.
RequestId string `xml:"RequestId"`
}
ErrorResponse is the AWS-style XML error body. It emits BOTH the EC2 query shape (<Errors><Error>...</Error></Errors>) and the standard query shape (<Error>...</Error> at the response root) so that:
- EC2 SDK (which parses xml:"Errors>Error>Code") finds the wrapped form.
- RDS / Redshift / Neptune / DocumentDB SDKs (which parse xml:"Error>Code" against a wrappedErrorResponse) find the unwrapped form.
The duplication is harmless: each SDK matches its own shape via XPath-style xml tags and ignores the other.