Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

Release/v1.3.38 (#635)

Nahuel Nucera382bb4bc7a83
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 94b4e0a5..e96288f1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,15 +7,20 @@ Versioning follows [Semantic Versioning](https://semver.org/).
---
-## [Unreleased]
+## [1.3.38] — 2026-05-13
### Added
-- **ECS task IAM role credentials endpoint (`GET /v2/credentials/<uuid>`)** — real ECS injects `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=/v2/credentials/<uuid>` per task and SDKs fetch credentials by GETting that path against `169.254.170.2`. MiniStack now serves the same path on the gateway and returns the IMDS-shape credentials document (`Code`, `LastUpdated`, `Type`, `AccessKeyId`, `SecretAccessKey`, `Token`, `Expiration`); the path-`<uuid>` segment is opaque and treated as the auth token, mirroring real ECS.
-- **ECS task env injection for SDK-driven workloads** — tasks launched by MiniStack's ECS emulator now also get `AWS_CONTAINER_CREDENTIALS_FULL_URI` (so SDKs in task containers fetch emulated credentials automatically from the new `/v2/credentials/<uuid>` endpoint), `AWS_CONTAINER_AUTHORIZATION_TOKEN` (satisfies botocore's allow-list when the gateway host is not loopback, e.g. `host.docker.internal` or a Docker bridge IP), and `AWS_ENDPOINT_URL` (so SDK service calls auto-route to the gateway). Together with the existing `ECS_CONTAINER_METADATA_URI_V4`, unmodified AWS SDKs running inside an emulated ECS task now use MiniStack end-to-end with no client config.
+- **ECS task IAM role credentials endpoint (`GET /v2/credentials/<uuid>`)** — real ECS injects `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=/v2/credentials/<uuid>` per task and SDKs fetch credentials by GETting that path against `169.254.170.2`. MiniStack now serves the same path on the gateway and returns the AWS-strict 5-field credentials document (`AccessKeyId`, `SecretAccessKey`, `Token`, `Expiration`, `RoleArn`) — distinct from the IMDS shape served at `/latest/meta-data/iam/security-credentials/<role>`. Contributed by @YakirOren.
+- **ECS task env injection for SDK-driven workloads** — tasks launched by MiniStack's ECS emulator now also get `AWS_CONTAINER_CREDENTIALS_FULL_URI` (so SDKs in task containers fetch emulated credentials automatically from the new `/v2/credentials/<uuid>` endpoint), `AWS_CONTAINER_AUTHORIZATION_TOKEN` (satisfies botocore's allow-list when the gateway host is not loopback, e.g. `host.docker.internal` or a Docker bridge IP), and `AWS_ENDPOINT_URL` (so SDK service calls auto-route to the gateway). Together with the existing `ECS_CONTAINER_METADATA_URI_V4`, unmodified AWS SDKs running inside an emulated ECS task now use MiniStack end-to-end with no client config. Contributed by @YakirOren.
+- **CloudFormation `AWS::CertificateManager::Certificate`** — provisions a Certificate record matching `RequestCertificate` shape. `Ref` resolves to the ARN; honours `DomainName`, `SubjectAlternativeNames`, `ValidationMethod`, `Tags`, `KeyAlgorithm`, `CertificateTransparencyLoggingPreference`. Closes a gap that blocked any HTTPS-related IaC stack from applying against MiniStack. Reported by @parv0888.
+- **CloudFormation `AWS::ElasticLoadBalancingV2::TargetGroup`** — MS' ALB CFN story was previously partial: `LoadBalancer` and `Listener` provisioned but `TargetGroup` was missing, leaving the listener with nothing to forward to. The new handler writes a target-group record matching `CreateTargetGroup`, with AWS-documented defaults (HTTP, port 80, health-check interval 30, healthy/unhealthy thresholds 5/2, matcher 200). `Tags` and `TargetGroupAttributes` honoured. Reported by @parv0888.
+- **CloudFormation `AWS::ElasticLoadBalancingV2::ListenerRule`** — host- and path-based ALB routing now provisions. Conditions accept both the flat `{Field, Values}` shape and CFN's per-field nested config form (`PathPatternConfig.Values`, `HostHeaderConfig.Values`, `HttpHeaderConfig`, `HttpRequestMethodConfig`, `QueryStringConfig`, `SourceIpConfig`). Actions support `forward` / `redirect` / `fixed-response`. Reported by @parv0888.
+- **CloudFormation `AWS::RDS::DBInstance`** — standalone DB instances (non-Aurora) and Aurora cluster members now provision. Writes a record matching `CreateDBInstance` (metadata-only, like the existing `AWS::RDS::DBCluster` handler — Docker container spawn remains on the CLI/SDK path). Aurora cluster members inherit master credentials from the cluster automatically. `Fn::GetAtt` returns `Endpoint.Address`, `Endpoint.Port`, `DbiResourceId`, `DBInstanceArn`. Reported by @parv0888.
+- **CloudFormation `AWS::StepFunctions::StateMachine` `Definition` and `DefinitionS3Location`** — CDK's `DefinitionBody.fromFile()` emits `DefinitionS3Location` referencing an S3 asset, and `DefinitionBody.fromString()` emits the inline `Definition` object; MiniStack previously honoured only `DefinitionString` and silently fell back to `{}`, producing `InvalidDefinition: StartAt state 'None' not found` at execution time. Both forms are now honoured, `DefinitionS3Location` is fetched from the in-memory S3 service, and `DefinitionSubstitutions` placeholders (`${KEY}`) are applied to the resolved definition. Reported by @youngkwangk.
### Fixed
-- **ECS `connectivityAt` and `stoppingAt` timestamps wire-formatted as numbers** — both fields are set on tasks but were missing from the `_ECS_TIMESTAMP_FIELDS` normalization set, so they shipped as ISO strings in `DescribeTasks` / `ListTasks` responses. The Go AWS SDK v2 (which strictly requires `Timestamp` to be a JSON number under the JSON 1.1 protocol) rejected the response with `deserialization failed, expected Timestamp to be a JSON Number, got string instead`. boto3 is lenient and accepted the strings, hiding the issue. Both fields are now epoch-normalized alongside the other task timestamps.
-- **CloudFormation `AWS::ECS::TaskDefinition` populates `registeredAt`, `registeredBy`, and `compatibilities`** — the CFN provisioner constructed the task-definition record without these three fields, so `DescribeTaskDefinition` returned them as missing for CFN-created TDs even though the equivalent CLI/SDK path (`RegisterTaskDefinition`) always set them. Workloads that read `registeredAt` (e.g. the ARMO ECS operator and other reconcilers) had to fall back to "now". The CFN path now mirrors the CLI path and emits the same three fields with the same values.
+- **ECS `connectivityAt` and `stoppingAt` timestamps wire-formatted as numbers** — both fields are set on tasks but were missing from the `_ECS_TIMESTAMP_FIELDS` normalization set, so they shipped as ISO strings in `DescribeTasks` / `ListTasks` responses. The Go AWS SDK v2 (strict JSON 1.1 timestamp parsing) rejected the response; boto3 was lenient and hid the issue. Both fields are now epoch-normalized alongside the other task timestamps. Contributed by @YakirOren.
+- **CloudFormation `AWS::ECS::TaskDefinition` populates `registeredAt`, `registeredBy`, and `compatibilities`** — the CFN provisioner constructed the task-definition record without these three fields, so `DescribeTaskDefinition` returned them as missing for CFN-created TDs even though the CLI/SDK path (`RegisterTaskDefinition`) always set them. Workloads that read `registeredAt` (e.g. the ARMO ECS operator and other reconcilers) had to fall back to "now". The CFN path now mirrors the CLI path. Contributed by @YakirOren.
## [1.3.37] — 2026-05-12
diff --git a/README.md b/README.md
index 6657f11c..0cf5d258 100644
--- a/README.md
+++ b/README.md
@@ -354,7 +354,7 @@ subnet = ec2.create_subnet(
| **STS** | GetCallerIdentity, AssumeRole, GetSessionToken, AssumeRoleWithWebIdentity | |
| **IMDS** (EC2 Instance Metadata) | `PUT /latest/api/token`, `GET /latest/meta-data/instance-id`, `GET /latest/meta-data/iam/security-credentials/`, `GET /latest/meta-data/iam/security-credentials/<role>`, `GET /latest/meta-data/iam/info`, `GET /latest/meta-data/placement/{region,availability-zone,...}`, `GET /latest/dynamic/instance-identity/document` | IMDSv1 + IMDSv2; default credential chain falls through to a `ministack-instance-role` document with `ASIA*` session creds. Point SDKs at ministack via `AWS_EC2_METADATA_SERVICE_ENDPOINT=http://localhost:4566` (or `ec2_metadata_service_endpoint` in `~/.aws/config`); set `MINISTACK_IMDS_V2_REQUIRED=1` to require the token PUT |
| **ECS Task Metadata V4** | `GET /v4/<token>`, `GET /v4/<token>/task`, `GET /v4/<token>/stats`, `GET /v4/<token>/task/stats` | Per-container token injected as `ECS_CONTAINER_METADATA_URI_V4` on every container started by `RunTask`. `/task` returns sibling containers in the same task. Containers reach the gateway via `host.docker.internal` (mapped through `extra_hosts: host-gateway`, so it works on user-defined Docker networks); `networkMode: host` containers use loopback. Volatile by design (stripped on persistence, cleared by `/_ministack/reset`) |
-| **ECS Container Credentials** | `GET /v2/credentials/<uuid>` | The path real ECS exposes via `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=/v2/credentials/<uuid>` (resolved by SDKs against `169.254.170.2`). MiniStack serves the same path on the gateway and returns the IMDS-shape credentials document (`Code`, `LastUpdated`, `Type`, `AccessKeyId`, `SecretAccessKey`, `Token`, `Expiration`). `RunTask` injects `AWS_CONTAINER_CREDENTIALS_FULL_URI`, `AWS_CONTAINER_AUTHORIZATION_TOKEN` (satisfies botocore's allow-list for non-loopback gateway hosts), and `AWS_ENDPOINT_URL` so unmodified SDKs inside the task fetch credentials and route service calls through MiniStack with no client config |
+| **ECS Container Credentials** | `GET /v2/credentials/<uuid>` | The path real ECS exposes via `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=/v2/credentials/<uuid>` (resolved by SDKs against `169.254.170.2`). MiniStack serves the same path on the gateway and returns the AWS-strict 5-field credentials document (`AccessKeyId`, `SecretAccessKey`, `Token`, `Expiration`, `RoleArn`) — distinct from the IMDS shape served at `/latest/meta-data/iam/security-credentials/<role>`. `RunTask` injects `AWS_CONTAINER_CREDENTIALS_FULL_URI`, `AWS_CONTAINER_AUTHORIZATION_TOKEN` (satisfies botocore's allow-list for non-loopback gateway hosts), and `AWS_ENDPOINT_URL` so unmodified SDKs inside the task fetch credentials and route service calls through MiniStack with no client config |
| **SecretsManager** | CreateSecret, GetSecretValue, ListSecrets, DeleteSecret, UpdateSecret, DescribeSecret, PutSecretValue, UpdateSecretVersionStage, RestoreSecret, RotateSecret, GetRandomPassword, ListSecretVersionIds, ReplicateSecretToRegions, TagResource, UntagResource, PutResourcePolicy, GetResourcePolicy, DeleteResourcePolicy, ValidateResourcePolicy | |
| **CloudWatch Logs** | CreateLogGroup, DeleteLogGroup, DescribeLogGroups, CreateLogStream, DeleteLogStream, DescribeLogStreams, PutLogEvents, GetLogEvents, FilterLogEvents, PutRetentionPolicy, DeleteRetentionPolicy, PutSubscriptionFilter, DeleteSubscriptionFilter, DescribeSubscriptionFilters, PutMetricFilter, DeleteMetricFilter, DescribeMetricFilters, TagLogGroup, UntagLogGroup, ListTagsLogGroup, TagResource, UntagResource, ListTagsForResource, StartQuery, GetQueryResults, StopQuery, PutDestination, DeleteDestination, DescribeDestinations, PutDestinationPolicy | `FilterLogEvents` supports `*`/`?` globs, multi-term AND, `-term` exclusion |
diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.py
index 65711b8a..6b5f97d4 100644
--- a/ministack/services/cloudformation/provisioners.py
+++ b/ministack/services/cloudformation/provisioners.py
@@ -14,6 +14,7 @@ import time
import zipfile
from collections import defaultdict
+import ministack.services.acm as _acm
import ministack.services.alb as _alb
import ministack.services.apigateway as _apigw_v2
import ministack.services.apigateway_v1 as _apigw_v1
@@ -2433,10 +2434,48 @@ def _lambda_layer_delete(physical_id, props):
def _sfn_state_machine_create(logical_id, props, stack_name):
name = props.get("StateMachineName") or _physical_name(stack_name, logical_id, max_len=80)
role_arn = props.get("RoleArn", f"arn:aws:iam::{get_account_id()}:role/StepFunctionsRole")
- definition = props.get("DefinitionString", "{}")
- if isinstance(definition, dict):
- import json as _json
- definition = _json.dumps(definition)
+ import json as _json
+
+ # Real CFN accepts three mutually-exclusive definition shapes:
+ # DefinitionString (inline JSON/YAML string — pre-existing)
+ # Definition (inline JSON object — CDK DefinitionBody.fromString uses this)
+ # DefinitionS3Location ({Bucket, Key, Version} — CDK DefinitionBody.fromFile uses this)
+ # DefinitionSubstitutions is a Map<String, String> applied to whichever
+ # source produced the definition; placeholders are `${KEY}` per the AWS spec.
+ definition = None
+ if props.get("DefinitionS3Location"):
+ loc = props["DefinitionS3Location"] or {}
+ bucket = loc.get("Bucket") or ""
+ key = loc.get("Key") or ""
+ version = loc.get("Version")
+ if bucket and key:
+ from ministack.services import s3 as _s3_svc
+ try:
+ blob = _s3_svc._get_object_data(bucket, key, version_id=version)
+ except Exception as e:
+ raise ValueError(
+ f"AWS::StepFunctions::StateMachine DefinitionS3Location fetch failed "
+ f"for s3://{bucket}/{key}: {e}"
+ )
+ if blob is None:
+ raise ValueError(
+ f"AWS::StepFunctions::StateMachine DefinitionS3Location object not found: "
+ f"s3://{bucket}/{key}"
+ )
+ definition = blob.decode("utf-8", errors="replace")
+ if definition is None and props.get("Definition") is not None:
+ d = props["Definition"]
+ definition = _json.dumps(d) if isinstance(d, (dict, list)) else str(d)
+ if definition is None:
+ definition = props.get("DefinitionString", "{}")
+ if isinstance(definition, dict):
+ definition = _json.dumps(definition)
+
+ subs = props.get("DefinitionSubstitutions") or {}
+ if subs:
+ for k, v in subs.items():
+ definition = definition.replace("${" + str(k) + "}", str(v))
+
sm_type = props.get("StateMachineType", "STANDARD")
arn = f"arn:aws:states:{get_region()}:{get_account_id()}:stateMachine:{name}"
@@ -2458,6 +2497,194 @@ def _sfn_state_machine_delete(physical_id, props):
_sfn._state_machines.pop(physical_id, None)
+# ---------------------------------------------------------------------------
+# AWS Certificate Manager (ACM)
+# ---------------------------------------------------------------------------
+
+def _acm_certificate_create(logical_id, props, stack_name):
+ """Provision an AWS::CertificateManager::Certificate.
+
+ Maps CFN props to acm._request_certificate: DomainName, SubjectAlternativeNames,
+ ValidationMethod, Tags. Returns the CertificateArn as the physical id, so
+ `Ref` resolves to the ARN (matching real CFN).
+ """
+ domain = props.get("DomainName", "")
+ if not domain:
+ raise ValueError(
+ "AWS::CertificateManager::Certificate requires DomainName"
+ )
+ sans = props.get("SubjectAlternativeNames") or [domain]
+ if isinstance(sans, str):
+ sans = [sans]
+ if domain not in sans:
+ sans = [domain] + list(sans)
+ method = props.get("ValidationMethod", "DNS")
+
+ arn = _acm._cert_arn()
+ now = now_iso()
+ _acm._certificates[arn] = {
+ "CertificateArn": arn,
+ "DomainName": domain,
+ "SubjectAlternativeNames": sans,
+ "Status": "ISSUED",
+ "Type": "AMAZON_ISSUED",
+ "CreatedAt": now,
+ "IssuedAt": now,
+ "NotBefore": now,
+ "NotAfter": _acm._future_iso(365 * 24 * 3600),
+ "DomainValidationOptions": [_acm._validation_options(d, method) for d in sans],
+ "ValidationMethod": method,
+ "Tags": props.get("Tags", []),
+ "Options": {
+ "CertificateTransparencyLoggingPreference":
+ (props.get("CertificateTransparencyLoggingPreference")
+ or (props.get("Options") or {}).get("CertificateTransparencyLoggingPreference")
+ or "ENABLED"),
+ },
+ "KeyAlgorithm": props.get("KeyAlgorithm", "RSA_2048"),
+ "_pem_body": _acm._synthetic_pem(domain),
+ "_pem_chain": "",
+ "_private_key": "",
+ }
+ return arn, {"CertificateArn": arn, "Arn": arn}
+
+
+def _acm_certificate_delete(physical_id, props):
+ _acm._certificates.pop(physical_id, None)
+
+
+# ---------------------------------------------------------------------------
+# ELBv2 TargetGroup + ListenerRule
+# ---------------------------------------------------------------------------
+
+def _elbv2_target_group_create(logical_id, props, stack_name):
+ """Provision an AWS::ElasticLoadBalancingV2::TargetGroup matching what
+ `CreateTargetGroup` produces; physical id = TargetGroupArn."""
+ name = props.get("Name") or _physical_name(stack_name, logical_id, max_len=32)
+ matcher = props.get("Matcher") or {}
+ import random as _random
+ import string as _string
+ tid = "".join(_random.choices(_string.ascii_lowercase + _string.digits, k=16))
+ arn = f"arn:aws:elasticloadbalancing:{get_region()}:{get_account_id()}:targetgroup/{name}/{tid}"
+ tg = {
+ "TargetGroupArn": arn,
+ "TargetGroupName": name,
+ "Protocol": props.get("Protocol", "HTTP"),
+ "Port": int(props.get("Port", 80) or 80),
+ "VpcId": props.get("VpcId", ""),
+ "HealthCheckProtocol": props.get("HealthCheckProtocol", "HTTP"),
+ "HealthCheckPort": props.get("HealthCheckPort", "traffic-port"),
+ "HealthCheckEnabled": (
+ props.get("HealthCheckEnabled", True)
+ if isinstance(props.get("HealthCheckEnabled"), bool)
+ else str(props.get("HealthCheckEnabled", "true")).lower() == "true"
+ ),
+ "HealthCheckPath": props.get("HealthCheckPath", "/"),
+ "HealthCheckIntervalSeconds": int(props.get("HealthCheckIntervalSeconds", 30) or 30),
+ "HealthCheckTimeoutSeconds": int(props.get("HealthCheckTimeoutSeconds", 5) or 5),
+ "HealthyThresholdCount": int(props.get("HealthyThresholdCount", 5) or 5),
+ "UnhealthyThresholdCount": int(props.get("UnhealthyThresholdCount", 2) or 2),
+ "Matcher": {"HttpCode": matcher.get("HttpCode", "200")},
+ "LoadBalancerArns": [],
+ "TargetType": props.get("TargetType", "instance"),
+ }
+ _alb._tgs[arn] = tg
+ _alb._targets[arn] = []
+ _alb._tags[arn] = {t["Key"]: t["Value"] for t in (props.get("Tags") or [])}
+ _alb._tg_attrs[arn] = [
+ {"Key": a.get("Key", ""), "Value": a.get("Value", "")}
+ for a in (props.get("TargetGroupAttributes") or [])
+ ] or [
+ {"Key": "deregistration_delay.timeout_seconds", "Value": "300"},
+ {"Key": "stickiness.enabled", "Value": "false"},
+ {"Key": "stickiness.type", "Value": "lb_cookie"},
+ ]
+ return arn, {"TargetGroupArn": arn, "TargetGroupName": name, "TargetGroupFullName": arn.split(":targetgroup/", 1)[-1]}
+
+
+def _elbv2_target_group_delete(physical_id, props):
+ _alb._tgs.pop(physical_id, None)
+ _alb._targets.pop(physical_id, None)
+ _alb._tags.pop(physical_id, None)
+ _alb._tg_attrs.pop(physical_id, None)
+
+
+def _flatten_listener_rule_conditions(cfn_conditions):
+ """CFN ListenerRule Conditions accept both the flat `{Field, Values}` shape
+ and the per-field nested config form (`PathPatternConfig.Values`,
+ `HostHeaderConfig.Values`, `HttpHeaderConfig`, `HttpRequestMethodConfig`,
+ `QueryStringConfig`, `SourceIpConfig`). MS' ALB stores the simple
+ `{Field, Values}` form, so collapse the nested form into Values for the
+ fields where it makes sense.
+ """
+ out = []
+ for c in cfn_conditions or []:
+ field = c.get("Field", "")
+ values = c.get("Values") or []
+ config_key = {
+ "path-pattern": "PathPatternConfig",
+ "host-header": "HostHeaderConfig",
+ "http-header": "HttpHeaderConfig",
+ "http-request-method": "HttpRequestMethodConfig",
+ "query-string": "QueryStringConfig",
+ "source-ip": "SourceIpConfig",
+ }.get(field)
+ if not values and config_key and c.get(config_key):
+ cfg = c[config_key]
+ values = cfg.get("Values") or []
+ if not values and field == "query-string" and cfg.get("Values") is None:
+ values = [f"{q.get('Key','')}={q.get('Value','')}" for q in (cfg.get("Values") or [])]
+ out.append({"Field": field, "Values": list(values)})
+ return out
+
+
+def _elbv2_listener_rule_create(logical_id, props, stack_name):
+ """Provision an AWS::ElasticLoadBalancingV2::ListenerRule. Conditions and
+ Actions match the shape MS' ALB stores in `_alb._rules`.
+ """
+ l_arn = props.get("ListenerArn", "")
+ if not l_arn:
+ raise ValueError("AWS::ElasticLoadBalancingV2::ListenerRule requires ListenerArn")
+ if l_arn not in _alb._listeners:
+ raise ValueError(f"Listener '{l_arn}' not found for ListenerRule {logical_id}")
+ listener = _alb._listeners[l_arn]
+ lb_arn = listener["LoadBalancerArn"]
+ lb_name = _alb._lbs[lb_arn]["LoadBalancerName"]
+ lb_id = lb_arn.split("/")[-1]
+ l_id = l_arn.split("/")[-1]
+ import random as _random
+ import string as _string
+ rule_id = "".join(_random.choices(_string.ascii_lowercase + _string.digits, k=16))
+ rule_arn = (f"arn:aws:elasticloadbalancing:{get_region()}:{get_account_id()}"
+ f":listener-rule/app/{lb_name}/{lb_id}/{l_id}/{rule_id}")
+ # CFN Actions: list of dicts with Type, Order, TargetGroupArn / RedirectConfig
+ # / FixedResponseConfig. MS' native shape matches this directly.
+ actions = []
+ for i, a in enumerate(props.get("Actions") or [], start=1):
+ record = {"Type": a.get("Type", "forward"), "Order": int(a.get("Order", i))}
+ if a.get("TargetGroupArn"):
+ record["TargetGroupArn"] = a["TargetGroupArn"]
+ if a.get("RedirectConfig"):
+ record["RedirectConfig"] = dict(a["RedirectConfig"])
+ if a.get("FixedResponseConfig"):
+ record["FixedResponseConfig"] = dict(a["FixedResponseConfig"])
+ actions.append(record)
+ rule = {
+ "RuleArn": rule_arn,
+ "ListenerArn": l_arn,
+ "Priority": str(props.get("Priority", 1)),
+ "Conditions": _flatten_listener_rule_conditions(props.get("Conditions") or []),
+ "Actions": actions,
+ "IsDefault": False,
+ }
+ _alb._rules[rule_arn] = rule
+ return rule_arn, {"RuleArn": rule_arn}
+
+
+def _elbv2_listener_rule_delete(physical_id, props):
+ _alb._rules.pop(physical_id, None)
+
+
# ---------------------------------------------------------------------------
# Route53 HostedZone
# ---------------------------------------------------------------------------
@@ -2989,6 +3216,149 @@ def _rds_db_cluster_delete(physical_id, props):
_rds._clusters.pop(physical_id, None)
+# ---------------------------------------------------------------------------
+# RDS DBInstance
+# ---------------------------------------------------------------------------
+
+def _rds_db_instance_create(logical_id, props, stack_name):
+ """Provision an AWS::RDS::DBInstance.
+
+ Writes the instance record directly into rds._instances with the same
+ shape `CreateDBInstance` produces, but does NOT spawn the Docker DB
+ container (CFN provisioning is metadata-only; real DB connectivity
+ happens via the CLI / SDK path which already handles container spawn).
+ """
+ db_id = props.get("DBInstanceIdentifier") or _physical_name(
+ stack_name, logical_id, lowercase=True, max_len=63
+ )
+ engine = props.get("Engine", "postgres")
+ engine_version = props.get("EngineVersion") or _rds._default_engine_version(engine)
+ db_class = props.get("DBInstanceClass", "db.t3.micro")
+ master_user = props.get("MasterUsername", "admin")
+ master_pass = props.get("MasterUserPassword", "password")
+ db_name = props.get("DBName", "")
+ cluster_id = props.get("DBClusterIdentifier", "")
+
+ # Aurora cluster members inherit master creds from the cluster.
+ if cluster_id and cluster_id in _rds._clusters:
+ parent = _rds._clusters[cluster_id]
+ master_user = props.get("MasterUsername") or parent.get("MasterUsername", master_user)
+ master_pass = props.get("MasterUserPassword") or parent.get("_MasterUserPassword", master_pass)
+ if not db_name:
+ db_name = parent.get("DatabaseName", "")
+
+ port = int(props.get("Port") or _rds._default_port(engine))
+ allocated_storage = int(props.get("AllocatedStorage") or 20)
+ storage_type = props.get("StorageType", "gp2")
+ subnet_group_name = props.get("DBSubnetGroupName", "default")
+ arn = f"arn:aws:rds:{get_region()}:{get_account_id()}:db:{db_id}"
+ dbi_resource_id = f"db-{new_uuid().replace('-', '')[:20].upper()}"
+ param_group_name = (
+ props.get("DBParameterGroupName")
+ or f"default.{engine}{engine_version.split('.')[0]}"
+ )
+
+ vpc_sgs = props.get("VPCSecurityGroups") or props.get("VpcSecurityGroupIds") or []
+ if isinstance(vpc_sgs, str):
+ vpc_sgs = [vpc_sgs]
+ vpc_sg_list = [{"VpcSecurityGroupId": sg, "Status": "active"} for sg in vpc_sgs]
+
+ subnet_group = _rds._subnet_groups.get(subnet_group_name, {
+ "DBSubnetGroupName": subnet_group_name,
+ "DBSubnetGroupDescription": "default",
+ "SubnetGroupStatus": "Complete",
+ "Subnets": [],
+ "VpcId": "vpc-00000000",
+ "DBSubnetGroupArn": f"arn:aws:rds:{get_region()}:{get_account_id()}:subgrp:{subnet_group_name}",
+ })
+
+ instance = {
+ "DBInstanceIdentifier": db_id,
+ "DBInstanceClass": db_class,
+ "Engine": engine,
+ "EngineVersion": engine_version,
+ "DBInstanceStatus": "available",
+ "MasterUsername": master_user,
+ "_MasterUserPassword": master_pass,
+ "DBName": db_name or "mydb",
+ "Endpoint": {
+ "Address": f"{db_id}.{new_uuid()[:8]}.{get_region()}.rds.amazonaws.com",
+ "Port": port,
+ "HostedZoneId": "Z2R2ITUGPM61AM",
+ },
+ "AllocatedStorage": allocated_storage,
+ "InstanceCreateTime": _rds._format_time(time.time()),
+ "PreferredBackupWindow": props.get("PreferredBackupWindow", "03:00-04:00"),
+ "BackupRetentionPeriod": int(props.get("BackupRetentionPeriod", 1)),
+ "DBSecurityGroups": [],
+ "VpcSecurityGroups": vpc_sg_list,
+ "DBParameterGroups": [{
+ "DBParameterGroupName": param_group_name,
+ "ParameterApplyStatus": "in-sync",
+ }],
+ "AvailabilityZone": props.get("AvailabilityZone", f"{get_region()}a"),
+ "DBSubnetGroup": subnet_group,
+ "PreferredMaintenanceWindow": props.get("PreferredMaintenanceWindow", "sun:05:00-sun:06:00"),
+ "PendingModifiedValues": {},
+ "MultiAZ": bool(props.get("MultiAZ", False)),
+ "AutoMinorVersionUpgrade": bool(props.get("AutoMinorVersionUpgrade", True)),
+ "ReadReplicaDBInstanceIdentifiers": [],
+ "ReadReplicaSourceDBInstanceIdentifier": "",
+ "LicenseModel": _rds._license_model(engine),
+ "OptionGroupMemberships": [{
+ "OptionGroupName": f"default:{engine}-{engine_version.split('.')[0]}",
+ "Status": "in-sync",
+ }],
+ "PubliclyAccessible": bool(props.get("PubliclyAccessible", False)),
+ "StorageType": storage_type,
+ "StorageEncrypted": bool(props.get("StorageEncrypted", False)),
+ "KmsKeyId": props.get("KmsKeyId", ""),
+ "DbiResourceId": dbi_resource_id,
+ "CACertificateIdentifier": "rds-ca-rsa2048-g1",
+ "CopyTagsToSnapshot": bool(props.get("CopyTagsToSnapshot", False)),
+ "MonitoringInterval": int(props.get("MonitoringInterval", 0)),
+ "MonitoringRoleArn": props.get("MonitoringRoleArn", ""),
+ "PromotionTier": int(props.get("PromotionTier", 1)),
+ "DBInstanceArn": arn,
+ "DBClusterIdentifier": cluster_id,
+ "IAMDatabaseAuthenticationEnabled": bool(props.get("EnableIAMDatabaseAuthentication", False)),
+ "DeletionProtection": bool(props.get("DeletionProtection", False)),
+ "PerformanceInsightsEnabled": bool(props.get("EnablePerformanceInsights", False)),
+ "TagList": props.get("Tags", []),
+ }
+ import time as _time
+ instance["LatestRestorableTime"] = _rds._format_time(_time.time())
+
+ _rds._instances[db_id] = instance
+ if cluster_id and cluster_id in _rds._clusters:
+ members = _rds._clusters[cluster_id].setdefault("DBClusterMembers", [])
+ if not any(m.get("DBInstanceIdentifier") == db_id for m in members):
+ members.append({
+ "DBInstanceIdentifier": db_id,
+ "IsClusterWriter": True,
+ "DBClusterParameterGroupStatus": "in-sync",
+ "PromotionTier": int(props.get("PromotionTier", 1)),
+ })
+
+ return db_id, {
+ "Endpoint.Address": instance["Endpoint"]["Address"],
+ "Endpoint.Port": str(port),
+ "DbiResourceId": dbi_resource_id,
+ "DBInstanceArn": arn,
+ }
+
+
+def _rds_db_instance_delete(physical_id, props):
+ instance = _rds._instances.pop(physical_id, None)
+ if instance:
+ cluster_id = instance.get("DBClusterIdentifier")
+ if cluster_id and cluster_id in _rds._clusters:
+ members = _rds._clusters[cluster_id].get("DBClusterMembers", [])
+ _rds._clusters[cluster_id]["DBClusterMembers"] = [
+ m for m in members if m.get("DBInstanceIdentifier") != physical_id
+ ]
+
+
# ---------------------------------------------------------------------------
# AutoScaling Group
# ---------------------------------------------------------------------------
@@ -3223,6 +3593,9 @@ _RESOURCE_HANDLERS = {
"AWS::Cognito::IdentityPool": {"create": _cognito_identity_pool_create, "delete": _cognito_identity_pool_delete},
"AWS::Cognito::UserPoolDomain": {"create": _cognito_user_pool_domain_create, "delete": _cognito_user_pool_domain_delete},
"AWS::ECR::Repository": {"create": _ecr_repo_create, "delete": _ecr_repo_delete},
+ "AWS::CertificateManager::Certificate": {"create": _acm_certificate_create, "delete": _acm_certificate_delete},
+ "AWS::ElasticLoadBalancingV2::TargetGroup": {"create": _elbv2_target_group_create, "delete": _elbv2_target_group_delete},
+ "AWS::ElasticLoadBalancingV2::ListenerRule": {"create": _elbv2_listener_rule_create, "delete": _elbv2_listener_rule_delete},
"AWS::CodeBuild::Project": {"create": _codebuild_project_create, "delete": _codebuild_project_delete},
"AWS::IAM::ManagedPolicy": {"create": _iam_managed_policy_create, "delete": _iam_managed_policy_delete},
"AWS::KMS::Key": {"create": _kms_key_create, "delete": _kms_key_delete},
@@ -3255,6 +3628,7 @@ _RESOURCE_HANDLERS = {
"AWS::CloudFront::KeyValueStore": {"create": _cf_kvs_create, "update": _cf_kvs_update, "delete": _cf_kvs_delete},
"AWS::CloudWatch::Alarm": {"create": _cw_metric_alarm_create, "delete": _cw_metric_alarm_delete},
"AWS::RDS::DBCluster": {"create": _rds_db_cluster_create, "delete": _rds_db_cluster_delete},
+ "AWS::RDS::DBInstance": {"create": _rds_db_instance_create, "delete": _rds_db_instance_delete},
# EventBridge Scheduler
"AWS::Scheduler::Schedule": {"create": _scheduler_schedule_create, "delete": _scheduler_schedule_delete},
"AWS::Scheduler::ScheduleGroup": {"create": _scheduler_group_create, "delete": _scheduler_group_delete},
diff --git a/ministack/services/imds.py b/ministack/services/imds.py
index 10e4feb1..64e277a3 100644
--- a/ministack/services/imds.py
+++ b/ministack/services/imds.py
@@ -87,6 +87,7 @@ def _issue_token(headers: dict):
def _credentials_doc() -> dict:
+ """EC2 IMDS credentials document shape (`/latest/meta-data/iam/security-credentials/<role>`)."""
return {
"Code": "Success",
"LastUpdated": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
@@ -98,6 +99,23 @@ def _credentials_doc() -> dict:
}
+def _ecs_task_credentials_doc() -> dict:
+ """ECS task IAM role credentials document shape (`/v2/credentials/<uuid>`).
+
+ Strict per AWS docs: AccessKeyId, SecretAccessKey, Token, Expiration, RoleArn.
+ No Code / Type / LastUpdated — those are EC2 IMDS-only and confuse strict
+ consumers that distinguish the two endpoints (e.g. some Go SDK behaviour
+ around iam.RoleName extraction).
+ """
+ return {
+ "AccessKeyId": _gen_session_access_key(),
+ "SecretAccessKey": _gen_secret(),
+ "Token": _gen_session_token(),
+ "Expiration": _future(3600),
+ "RoleArn": f"arn:aws:iam::{get_account_id()}:role/ministack-ecs-task-role",
+ }
+
+
def _identity_document() -> dict:
return {
"accountId": get_account_id(),
@@ -139,7 +157,7 @@ async def handle_request(method, path, headers, body, query_params):
if path.startswith("/v2/credentials/"):
if method != "GET":
return _text("Method Not Allowed", 405)
- return _json_resp(_credentials_doc())
+ return _json_resp(_ecs_task_credentials_doc())
if path.startswith("/latest/api/token"):
if method != "PUT":
diff --git a/pyproject.toml b/pyproject.toml
index 514bcbbc..9c979d2b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "ministack"
-version = "1.3.37"
+version = "1.3.38"
description = "Free, open-source local AWS emulator — drop-in LocalStack replacement"
readme = "README.md"
license = { file = "LICENSE" }
diff --git a/tests/test_imds.py b/tests/test_imds.py
index fc9229f8..843b8b0c 100644
--- a/tests/test_imds.py
+++ b/tests/test_imds.py
@@ -70,15 +70,20 @@ def test_imds_placement_region():
assert r.text.strip()
-def test_container_credentials_returns_imds_shape():
- """ECS task role endpoint: AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=/v2/credentials/<uuid>."""
+def test_container_credentials_returns_ecs_strict_shape():
+ """ECS task role endpoint: AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=/v2/credentials/<uuid>.
+ Real AWS returns the strict 5-field shape (AccessKeyId, SecretAccessKey,
+ Token, Expiration, RoleArn). The IMDS-only fields (Code, Type, LastUpdated)
+ must NOT be present — distinguishing the ECS endpoint from the EC2 IMDS
+ endpoint at /latest/meta-data/iam/security-credentials/<role>."""
r = requests.get(f"{ENDPOINT}/v2/credentials/68e5868d-1bde-4f9e-9921-6e0442cb567b")
assert r.status_code == 200
doc = r.json()
- assert doc["Code"] == "Success"
- assert doc["Type"] == "AWS-HMAC"
- for k in ("AccessKeyId", "SecretAccessKey", "Token", "Expiration", "LastUpdated"):
- assert k in doc and doc[k]
+ for k in ("AccessKeyId", "SecretAccessKey", "Token", "Expiration", "RoleArn"):
+ assert k in doc and doc[k], f"missing or empty: {k}"
+ assert doc["RoleArn"].startswith("arn:aws:iam::") and ":role/" in doc["RoleArn"]
+ for k in ("Code", "Type", "LastUpdated"):
+ assert k not in doc, f"{k} is IMDS-only and must not leak into the ECS endpoint"
def test_container_credentials_requires_id_segment():