rds

package
v0.0.1-alpha.37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package rds provides emulation of Amazon RDS.

Implemented: CreateDBInstance, DescribeDBInstances, DeleteDBInstance, DescribeDBEngineVersions, StopDBInstance, StartDBInstance, ModifyDBInstance, DescribeEvents, CreateDBSubnetGroup, DeleteDBSubnetGroup, DescribeDBSubnetGroups, CreateDBParameterGroup, DeleteDBParameterGroup, DescribeDBParameterGroups, DescribeOrderableDBInstanceOptions. All other operations return HTTP 501 Not Implemented.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DBCluster

type DBCluster struct {
	DBClusterIdentifier string `json:"DBClusterIdentifier"`
	DBClusterArn        string `json:"DBClusterArn"`
	Engine              string `json:"Engine"`
	EngineVersion       string `json:"EngineVersion"`
	Status              string `json:"Status"`
	MasterUsername      string `json:"MasterUsername"`
	// MasterUserPassword is the password the cluster's members answer to. A
	// cluster has no engine of its own, so this is not what a connection uses
	// — it is what tells a later ModifyDBCluster whether the password is
	// really changing, and it is never returned on the wire.
	MasterUserPassword string            `json:"MasterUserPassword,omitempty"`
	DatabaseName       string            `json:"DatabaseName,omitempty"`
	Port               int               `json:"Port"`
	Endpoint           string            `json:"Endpoint,omitempty"`
	ReaderEndpoint     string            `json:"ReaderEndpoint,omitempty"`
	MultiAZ            bool              `json:"MultiAZ"`
	StorageType        string            `json:"StorageType"`
	ClusterCreateTime  string            `json:"ClusterCreateTime,omitempty"`
	DBClusterMembers   []DBClusterMember `json:"DBClusterMembers,omitempty"`
	DBSubnetGroupName  string            `json:"DBSubnetGroup,omitempty"`

	// Settings ModifyDBCluster can change. They are recorded and reported
	// because that is what the AWS management plane does with them, and
	// because a stack update that changes one has to be able to show that it
	// landed. What sits behind them differs:
	//
	//   - DeletionProtection is enforced: DeleteDBCluster refuses a protected
	//     cluster, as AWS does.
	//   - BackupRetentionPeriod is validated against AWS's documented 1-35 and
	//     defaults to 1, then recorded only; PreferredBackupWindow and
	//     PreferredMaintenanceWindow are recorded only — Overcast takes no
	//     backups and has no maintenance window to schedule anything in.
	//   - DBClusterParameterGroup and VpcSecurityGroupIds are recorded only;
	//     neither engine parameters nor security groups are applied to the
	//     containers behind a cluster.
	//   - EnabledCloudwatchLogsExports is recorded only; no engine log is
	//     shipped to CloudWatch Logs.
	//
	// docs/services/rds.md carries the same list for users.
	BackupRetentionPeriod        int      `json:"BackupRetentionPeriod,omitempty"`
	PreferredBackupWindow        string   `json:"PreferredBackupWindow,omitempty"`
	PreferredMaintenanceWindow   string   `json:"PreferredMaintenanceWindow,omitempty"`
	DBClusterParameterGroup      string   `json:"DBClusterParameterGroup,omitempty"`
	VpcSecurityGroupIds          []string `json:"VpcSecurityGroupIds,omitempty"`
	EnabledCloudwatchLogsExports []string `json:"EnabledCloudwatchLogsExports,omitempty"`
	DeletionProtection           bool     `json:"DeletionProtection,omitempty"`
}

DBCluster represents a stored Aurora DB cluster.

It deliberately carries no PubliclyAccessible. On AWS that field belongs to the instance: an Aurora cluster has no network placement of its own, and CreateDBCluster only accepts it for Multi-AZ DB clusters, the non-Aurora deployment. createDBClusterTyped refuses any engine outside auroraEngines, so that shape cannot be created here, and the field stays on the members.

type DBClusterMember

type DBClusterMember struct {
	DBInstanceIdentifier          string `json:"DBInstanceIdentifier"`
	IsClusterWriter               bool   `json:"IsClusterWriter"`
	DBClusterParameterGroupStatus string `json:"DBClusterParameterGroupStatus"`
	PromotionTier                 int    `json:"PromotionTier"`
}

DBClusterMember represents one DB instance that belongs to an Aurora cluster.

type DBEvent

type DBEvent struct {
	SourceIdentifier string    `json:"SourceIdentifier"`
	SourceType       string    `json:"SourceType"`
	SourceArn        string    `json:"SourceArn,omitempty"`
	Message          string    `json:"Message"`
	EventCategories  []string  `json:"EventCategories,omitempty"`
	Date             time.Time `json:"Date"`
}

DBEvent is a stored RDS event — the channel AWS provides for "why did that happen to my database". DescribeEvents renders these; nothing else does.

type DBInstance

type DBInstance struct {
	DBInstanceIdentifier string `json:"DBInstanceIdentifier"`
	DBInstanceClass      string `json:"DBInstanceClass"`
	Engine               string `json:"Engine"`
	EngineVersion        string `json:"EngineVersion"`
	DBInstanceStatus     string `json:"DBInstanceStatus"`
	// StoppedByUser distinguishes StopDBInstance from a Docker-driven stop.
	// Reconciliation restores missing runtime for the latter, but must preserve
	// the former across Overcast restarts. Older records decode to false, which
	// recovers instances stranded by the pre-fix shutdown sweep.
	StoppedByUser bool `json:"StoppedByUser,omitempty"`
	// DockerRecoveryPending records desired-state recovery that could not yet
	// complete, most notably when the daemon disappears between its die event
	// and the restart call. A later daemon reconnect may retry only these failed
	// instances rather than restarting every genuinely failed database boot.
	DockerRecoveryPending bool `json:"DockerRecoveryPending,omitempty"`
	// DockerRecoveryAttempts bounds automatic restarts of an engine that keeps
	// exiting. It is cleared only after the recovered engine remains available
	// for a stability period, so a process that briefly opens its port before
	// crashing cannot reset its own circuit breaker.
	DockerRecoveryAttempts int `json:"DockerRecoveryAttempts,omitempty"`
	// DockerRecoveryAvailableAt makes the stability window survive an Overcast
	// restart. The reset timer is process-local, but a later recovery can still
	// tell that the engine stayed available long enough to earn a fresh budget.
	DockerRecoveryAvailableAt time.Time `json:"DockerRecoveryAvailableAt,omitempty"`
	// StatusReason is why the instance is in a failure status. It is
	// deliberately absent from the DescribeDBInstances wire shape: the real
	// DBInstance carries no such field, and StatusInfos is documented as
	// read-replica-only. AWS exposes a failure reason through RDS events, and
	// this is the text those events carry.
	StatusReason       string    `json:"StatusReason,omitempty"`
	MasterUsername     string    `json:"MasterUsername"`
	MasterUserPassword string    `json:"MasterUserPassword,omitempty"`
	DBName             string    `json:"DBName,omitempty"`
	AllocatedStorage   int       `json:"AllocatedStorage"`
	Endpoint           *Endpoint `json:"Endpoint,omitempty"`
	DBInstanceArn      string    `json:"DBInstanceArn"`
	InstanceCreateTime string    `json:"InstanceCreateTime,omitempty"`
	MultiAZ            bool      `json:"MultiAZ"`
	StorageType        string    `json:"StorageType"`
	Port               int       `json:"Port"`
	DockerContainerID  string    `json:"DockerContainerID,omitempty"`
	HostPort           int       `json:"HostPort,omitempty"`
	// DialAddress/DialPort are how *Overcast* reaches the engine container
	// (health checks), which is not what any client is told: see dialTarget and
	// instanceEndpointFor in endpoint.go.
	DialAddress         string `json:"DialAddress,omitempty"`
	DialPort            int    `json:"DialPort,omitempty"`
	DBClusterIdentifier string `json:"DBClusterIdentifier,omitempty"`
	DBSubnetGroupName   string `json:"DBSubnetGroupName,omitempty"`
	VpcID               string `json:"VpcId,omitempty"`
	// PubliclyAccessible is whether the instance is meant to be reachable from
	// outside the VPC it was placed in. CreateDBInstance always writes one and
	// ModifyDBInstance can change it, so on a live record it is never nil.
	//
	// It is a pointer for the records that predate the field: those never
	// answered the question, and decoding them to false would quietly declare
	// every instance now running private — which, once VPC placement is
	// enforced, is a database that stops answering after an upgrade nobody
	// connected to it. Nil therefore means "unstated" and is resolved by the
	// same rule a create would have used. Read it through
	// PubliclyAccessibleOrDefault rather than dereferencing it.
	PubliclyAccessible *bool `json:"PubliclyAccessible,omitempty"`
	// LastLogs is a bounded tail of the container's own output, kept from the
	// moment the container stopped answering. Docker discards a removed
	// container's logs, and the whole reason anyone opens the logs of a
	// database that would not start is to read the lines that explain why —
	// so they are copied onto the record while they still exist. Bounded by
	// maxRetainedLogBytes; LastLogsAt says when the copy was taken.
	LastLogs   string `json:"LastLogs,omitempty"`
	LastLogsAt string `json:"LastLogsAt,omitempty"`
}

DBInstance represents a stored RDS DB instance.

func (*DBInstance) PubliclyAccessibleOrDefault

func (i *DBInstance) PubliclyAccessibleOrDefault() bool

PubliclyAccessibleOrDefault reports whether the instance is meant to be reachable from outside its VPC, deciding an unstated one exactly as CreateDBInstance would have. Every reader — the wire, and anything that decides where a container is attached — goes through here, so a stored nil cannot mean one thing in a response and another in placement.

type DBParameterGroup

type DBParameterGroup struct {
	DBParameterGroupName   string `json:"dbParameterGroupName"`
	DBParameterGroupFamily string `json:"dbParameterGroupFamily"`
	Description            string `json:"description"`
	DBParameterGroupArn    string `json:"dbParameterGroupArn"`
}

DBParameterGroup represents a stored RDS DB parameter group.

type DBSubnetGroup

type DBSubnetGroup struct {
	DBSubnetGroupName        string   `json:"DBSubnetGroupName"`
	DBSubnetGroupDescription string   `json:"DBSubnetGroupDescription"`
	DBSubnetGroupArn         string   `json:"DBSubnetGroupArn"`
	VpcId                    string   `json:"VpcId"`
	SubnetIds                []string `json:"SubnetIds"`
	Status                   string   `json:"Status"`
}

DBSubnetGroup represents a stored RDS DB subnet group.

type Endpoint

type Endpoint struct {
	Address string `json:"Address"`
	Port    int    `json:"Port"`
}

Endpoint represents the connection endpoint for a DB instance.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler handles RDS Query-protocol requests.

func (*Handler) AddTagsToResource

func (h *Handler) AddTagsToResource(w http.ResponseWriter, r *http.Request)

func (*Handler) CreateDBCluster

func (h *Handler) CreateDBCluster(w http.ResponseWriter, r *http.Request)

CreateDBCluster creates a new Aurora DB cluster. Only aurora-mysql and aurora-postgresql engines are accepted. The cluster is a logical resource — Docker containers are started when instances are added via CreateDBInstance.

An adapter, for the reason given on ModifyDBCluster: this was a second full implementation, and it read none of the settings the typed one accepts, so a create arriving on this path would have discarded every one of them — including the master password the cluster has to remember in order to know, later, whether a rotation is really a change.

func (*Handler) CreateDBClusterSnapshot

func (h *Handler) CreateDBClusterSnapshot(w http.ResponseWriter, r *http.Request)

CreateDBClusterSnapshot creates a snapshot of an Aurora DB cluster.

func (*Handler) CreateDBInstance

func (h *Handler) CreateDBInstance(w http.ResponseWriter, r *http.Request)

CreateDBInstance creates a DB instance.

func (*Handler) CreateDBParameterGroup

func (h *Handler) CreateDBParameterGroup(w http.ResponseWriter, r *http.Request)

CreateDBParameterGroup creates a new DB parameter group.

func (*Handler) CreateDBSnapshot

func (h *Handler) CreateDBSnapshot(w http.ResponseWriter, r *http.Request)

CreateDBSnapshot creates a snapshot of a DB instance.

func (*Handler) CreateDBSubnetGroup

func (h *Handler) CreateDBSubnetGroup(w http.ResponseWriter, r *http.Request)

CreateDBSubnetGroup creates a new DB subnet group.

func (*Handler) DeleteDBCluster

func (h *Handler) DeleteDBCluster(w http.ResponseWriter, r *http.Request)

DeleteDBCluster deletes an Aurora DB cluster. The cluster is marked "deleting" immediately and removed asynchronously. Member instances are not automatically deleted — callers should delete instances first (matching AWS behaviour). An adapter, and necessarily one: the typed implementation refuses a cluster with DeletionProtection enabled, and a second implementation that did not would make the protection bypassable by choosing a dispatch path.

func (*Handler) DeleteDBClusterSnapshot

func (h *Handler) DeleteDBClusterSnapshot(w http.ResponseWriter, r *http.Request)

DeleteDBClusterSnapshot deletes a DB cluster snapshot.

func (*Handler) DeleteDBInstance

func (h *Handler) DeleteDBInstance(w http.ResponseWriter, r *http.Request)

DeleteDBInstance deletes a DB instance.

func (*Handler) DeleteDBParameterGroup

func (h *Handler) DeleteDBParameterGroup(w http.ResponseWriter, r *http.Request)

DeleteDBParameterGroup deletes a DB parameter group.

func (*Handler) DeleteDBSnapshot

func (h *Handler) DeleteDBSnapshot(w http.ResponseWriter, r *http.Request)

DeleteDBSnapshot deletes a DB snapshot.

func (*Handler) DeleteDBSubnetGroup

func (h *Handler) DeleteDBSubnetGroup(w http.ResponseWriter, r *http.Request)

DeleteDBSubnetGroup deletes a DB subnet group.

func (*Handler) DescribeDBClusterSnapshots

func (h *Handler) DescribeDBClusterSnapshots(w http.ResponseWriter, r *http.Request)

DescribeDBClusterSnapshots returns information about DB cluster snapshots.

func (*Handler) DescribeDBClusters

func (h *Handler) DescribeDBClusters(w http.ResponseWriter, r *http.Request)

DescribeDBClusters returns Aurora DB clusters, optionally filtered by identifier.

func (*Handler) DescribeDBEngineVersions

func (h *Handler) DescribeDBEngineVersions(w http.ResponseWriter, r *http.Request)

DescribeDBEngineVersions returns the supported engine versions.

func (*Handler) DescribeDBInstances

func (h *Handler) DescribeDBInstances(w http.ResponseWriter, r *http.Request)

DescribeDBInstances returns DB instances, optionally filtered by identifier.

func (*Handler) DescribeDBLogFiles

func (h *Handler) DescribeDBLogFiles(w http.ResponseWriter, r *http.Request)

DescribeDBLogFiles returns a list of DB log files for the DB instance.

func (*Handler) DescribeDBParameterGroups

func (h *Handler) DescribeDBParameterGroups(w http.ResponseWriter, r *http.Request)

DescribeDBParameterGroups returns DB parameter groups, optionally filtered by name.

func (*Handler) DescribeDBSnapshots

func (h *Handler) DescribeDBSnapshots(w http.ResponseWriter, r *http.Request)

DescribeDBSnapshots returns information about DB snapshots.

func (*Handler) DescribeDBSubnetGroups

func (h *Handler) DescribeDBSubnetGroups(w http.ResponseWriter, r *http.Request)

DescribeDBSubnetGroups returns DB subnet groups, optionally filtered by name.

func (*Handler) DescribeEvents

func (h *Handler) DescribeEvents(w http.ResponseWriter, r *http.Request)

DescribeEvents is the raw Query entry point; it delegates to the typed implementation so the two dispatch paths cannot drift.

func (*Handler) DescribeOrderableDBInstanceOptions

func (h *Handler) DescribeOrderableDBInstanceOptions(w http.ResponseWriter, r *http.Request)

DescribeOrderableDBInstanceOptions returns static orderable instance options.

func (*Handler) DownloadDBLogFilePortion

func (h *Handler) DownloadDBLogFilePortion(w http.ResponseWriter, r *http.Request)

DownloadDBLogFilePortion downloads all or a portion of a specified log file.

func (*Handler) GetInstanceLogs

func (h *Handler) GetInstanceLogs(w http.ResponseWriter, r *http.Request)

GetInstanceLogs returns the last 200 lines of logs for an RDS instance's Docker container, falling back to the tail retained when that container died. This is an emulator-only endpoint.

func (*Handler) ListTagsForResource

func (h *Handler) ListTagsForResource(w http.ResponseWriter, r *http.Request)

func (*Handler) ModifyDBCluster

func (h *Handler) ModifyDBCluster(w http.ResponseWriter, r *http.Request)

ModifyDBCluster updates settings on an Aurora DB cluster.

This was a second full implementation, reachable whenever Service.DispatchQuery found no codec in context and fell back to h.dispatch. It read exactly one parameter, as the typed one did, so the two agreed by accident rather than by construction — and the moment the typed one learned to apply the rest of ModifyDBCluster's parameters they would have disagreed about every one of them. It is an adapter now, for the same reason the instance operations became adapters; the behaviour lives once, in typed_logic.go.

func (*Handler) ModifyDBInstance

func (h *Handler) ModifyDBInstance(w http.ResponseWriter, r *http.Request)

ModifyDBInstance modifies metadata properties of an existing DB instance.

func (*Handler) RebootDBInstance

func (h *Handler) RebootDBInstance(w http.ResponseWriter, r *http.Request)

RebootDBInstance reboots a DB instance.

func (*Handler) RemoveTagsFromResource

func (h *Handler) RemoveTagsFromResource(w http.ResponseWriter, r *http.Request)

func (*Handler) RestoreDBInstanceFromDBSnapshot

func (h *Handler) RestoreDBInstanceFromDBSnapshot(w http.ResponseWriter, r *http.Request)

RestoreDBInstanceFromDBSnapshot restores a DB instance from a snapshot.

func (*Handler) StartDBCluster

func (h *Handler) StartDBCluster(w http.ResponseWriter, r *http.Request)

StartDBCluster starts a stopped Aurora DB cluster.

An adapter, for the reason given on the other four: this was a second full implementation, and the two disagreed about the one thing neither could see. The typed one answered in a CreateDBClusterResponse envelope; this one built the right envelope from a locally declared type, so whichever you read looked correct and only the dispatch path decided which an SDK got.

func (*Handler) StartDBInstance

func (h *Handler) StartDBInstance(w http.ResponseWriter, r *http.Request)

StartDBInstance starts a previously stopped DB instance.

func (*Handler) StopDBCluster

func (h *Handler) StopDBCluster(w http.ResponseWriter, r *http.Request)

StopDBCluster stops a running Aurora DB cluster. An adapter, for the reason given on StartDBCluster.

func (*Handler) StopDBInstance

func (h *Handler) StopDBInstance(w http.ResponseWriter, r *http.Request)

StopDBInstance stops a running DB instance.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service implements router.Service and router.QueryDispatcher for RDS. Uses the AWS Query protocol (form-encoded POST, XML responses) and identifies itself by the API version "2014-10-31".

func New

func New(cfg *config.Config, store state.Store, logger *zap.Logger, clk clock.Clock) *Service

New returns a configured RDS Service.

func (*Service) DispatchQuery

func (s *Service) DispatchQuery(w http.ResponseWriter, r *http.Request)

DispatchQuery satisfies router.QueryDispatcher; routes to the correct handler.

func (*Service) InitBus

func (s *Service) InitBus(bus *events.Bus)

InitBus wires the event bus for RDS lifecycle events and subscribes to Docker container events so instance status stays in sync with container state.

func (*Service) Name

func (s *Service) Name() string

Name satisfies router.Service.

func (*Service) Operations

func (s *Service) Operations() []op.Operation

Operations implements router.ProtocolService.

func (*Service) OwnsAction

func (s *Service) OwnsAction(action string) bool

OwnsAction satisfies router.QueryActionOwner.

func (*Service) OwnsVersion

func (s *Service) OwnsVersion(version string) bool

OwnsVersion satisfies router.QueryVersionOwner.

func (*Service) ReconcileContainers

func (s *Service) ReconcileContainers(ctx context.Context, containers []docker.ContainerSummary)

ReconcileContainers satisfies router.ContainerReconciler. Startup and reconnect snapshots repair stored RDS instance state and replace missing database containers.

func (*Service) RegisterRoutes

func (s *Service) RegisterRoutes(r chi.Router)

RegisterRoutes satisfies router.Service. Registers emulator-only endpoints.

func (*Service) SetDocker

func (s *Service) SetDocker(dc *docker.Client)

SetDocker wires the Docker client for RDS container management and starts the DockGC background remove loop.

Mock mode declines the client rather than filtering its use at each call site: everything downstream already keys off dockerReady, so leaving it unset is the one change that makes every path metadata-only at once. The router normally does not even probe Docker for RDS in mock mode; this guard makes the mode hold whoever calls.

func (*Service) SetVPCResolver

func (s *Service) SetVPCResolver(r VPCNetworkResolver)

SetVPCResolver wires the EC2 VPC resolver for DB subnet group launches.

func (*Service) Stop

func (s *Service) Stop(ctx context.Context)

Stop cancels pending lifecycle transitions and cleans up Docker containers via the GC. The GC does a Docker-level sweep so even orphaned containers (whose store record was already deleted) are caught and removed.

func (*Service) SupportedProtocols

func (s *Service) SupportedProtocols() []codec.Codec

SupportedProtocols implements router.ProtocolService.

type VPCNetworkResolver

type VPCNetworkResolver interface {
	VpcIDForSubnet(ctx context.Context, subnetID string) string
	VPCNetworkStatus(ctx context.Context, vpcID string) string
	DockerNetworkForVpc(ctx context.Context, vpcID string) string
}

VPCNetworkResolver resolves DB subnet groups back to EC2 VPC network state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL