Skip to content

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

feat(appconfig): add AppConfig service emulator (#284)

alexanderkrum-next305838ac1fb9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 246abb8d..c3902c28 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,9 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- **`.py` init scripts** — ready.d and boot.d directories now support Python scripts in addition to shell scripts. Files ending in `.py` are executed with the container's Python interpreter. Contributed by @AdigaAkhil (#272)
- **Init script environment defaults** — init scripts automatically receive `AWS_ACCESS_KEY_ID=test`, `AWS_SECRET_ACCESS_KEY=test`, `AWS_DEFAULT_REGION`, and `AWS_ENDPOINT_URL` so `aws` CLI and boto3 work out of the box without manual configuration.
+### Added
+- **AppConfig service emulator** — full control plane (applications, environments, configuration profiles, hosted configuration versions, deployment strategies, deployments, tags) and data plane (`StartConfigurationSession`, `GetLatestConfiguration`). 33 operations across both `appconfig` and `appconfigdata` API surfaces. Deployments complete immediately; session-based configuration retrieval with token rotation matches real AWS behavior.
+
### Fixed
- **Health check log noise** — health endpoint access logs (`/_ministack/health`, `/_localstack/health`, `/health`) are now suppressed at `LOG_LEVEL=INFO`. Visible at `LOG_LEVEL=DEBUG`. Reported by @McDoit
diff --git a/README.md b/README.md
index 6ae482cf..00597bf9 100644
--- a/README.md
+++ b/README.md
@@ -474,6 +474,7 @@ Unsupported resource types fail with `CREATE_FAILED` (or `ROLLBACK_COMPLETE` if
| **S3 Files** | CreateFileSystem, GetFileSystem, ListFileSystems, DeleteFileSystem, CreateMountTarget, GetMountTarget, ListMountTargets, UpdateMountTarget, DeleteMountTarget, CreateAccessPoint, GetAccessPoint, ListAccessPoints, DeleteAccessPoint, GetFileSystemPolicy, PutFileSystemPolicy, DeleteFileSystemPolicy, GetSynchronizationConfiguration, PutSynchronizationConfiguration, TagResource, UntagResource, ListTagsForResource | 21 operations; control plane for the new S3 Files service (launched April 2026); file systems, mount targets, access points, policies |
| **AutoScaling** | CreateAutoScalingGroup, DescribeAutoScalingGroups, UpdateAutoScalingGroup, DeleteAutoScalingGroup, DescribeAutoScalingInstances, CreateLaunchConfiguration, DescribeLaunchConfigurations, DeleteLaunchConfiguration, PutScalingPolicy, DescribePolicies, DeletePolicy, PutLifecycleHook, DescribeLifecycleHooks, DeleteLifecycleHook, CompleteLifecycleAction, RecordLifecycleActionHeartbeat, PutScheduledUpdateGroupAction, DescribeScheduledActions, DeleteScheduledAction, CreateOrUpdateTags, DescribeTags, DeleteTags | 22 actions; in-memory state — no real instance scaling; full ASG lifecycle (launch configs, scaling policies, lifecycle hooks, scheduled actions, tags); CDK/Terraform compatible |
| **CodeBuild** | CreateProject, BatchGetProjects, ListProjects, UpdateProject, DeleteProject, StartBuild, BatchGetBuilds, StopBuild, ListBuilds, ListBuildsForProject, BatchDeleteBuilds | 11 actions; builds complete immediately with SUCCEEDED status; project and build metadata stored in-memory |
+| **AppConfig** | CreateApplication, GetApplication, ListApplications, UpdateApplication, DeleteApplication, CreateEnvironment, GetEnvironment, ListEnvironments, UpdateEnvironment, DeleteEnvironment, CreateConfigurationProfile, GetConfigurationProfile, ListConfigurationProfiles, UpdateConfigurationProfile, DeleteConfigurationProfile, CreateHostedConfigurationVersion, GetHostedConfigurationVersion, ListHostedConfigurationVersions, DeleteHostedConfigurationVersion, CreateDeploymentStrategy, GetDeploymentStrategy, ListDeploymentStrategies, UpdateDeploymentStrategy, DeleteDeploymentStrategy, StartDeployment, GetDeployment, ListDeployments, StopDeployment, TagResource, UntagResource, ListTagsForResource, StartConfigurationSession, GetLatestConfiguration | 33 operations; control plane + data plane; hosted configuration versions; deployments complete immediately; session-based configuration retrieval with token rotation |
---
diff --git a/ministack/app.py b/ministack/app.py
index c7df3a4b..9eb29f52 100644
--- a/ministack/app.py
+++ b/ministack/app.py
@@ -46,6 +46,7 @@ from ministack.services import (
apigateway,
autoscaling,
apigateway_v1,
+ appconfig,
appsync,
athena,
cloudformation,
@@ -135,6 +136,8 @@ SERVICE_HANDLERS = {
"s3files": s3files.handle_request,
"rds-data": rds_data.handle_request,
"autoscaling": autoscaling.handle_request,
+ "appconfig": appconfig.handle_request,
+ "appconfigdata": appconfig.handle_request,
}
SERVICE_NAME_ALIASES = {
@@ -190,7 +193,7 @@ BANNER = r"""
SSM, EventBridge, Kinesis, CloudWatch, SES, SES v2, ACM, WAF v2, Step Functions,
ECS, RDS, ElastiCache, Glue, Athena, API Gateway, Firehose, Route53,
Cognito, EC2, EMR, EBS, EFS, ALB/ELBv2, CloudFormation, KMS, ECR, CloudFront,
- AppSync, Cloud Map, S3 Files, RDS Data API, CodeBuild
+ AppSync, Cloud Map, S3 Files, RDS Data API, CodeBuild, AppConfig
"""
@@ -636,6 +639,7 @@ async def _handle_lifespan(scope, receive, send):
"ses_v2": ses_v2.get_state,
"servicediscovery": servicediscovery.get_state,
"s3files": s3files.get_state,
+ "appconfig": appconfig.get_state,
})
_stop_docker_containers()
await send({"type": "lifespan.shutdown.complete"})
@@ -809,6 +813,7 @@ def _reset_all_state():
(servicediscovery, servicediscovery.reset),
(rds_data, rds_data.reset),
(s3files, s3files.reset),
+ (appconfig, appconfig.reset),
]:
try:
fn()
diff --git a/ministack/core/router.py b/ministack/core/router.py
index d31570c6..27ff5c72 100644
--- a/ministack/core/router.py
+++ b/ministack/core/router.py
@@ -190,6 +190,16 @@ SERVICE_PATTERNS = {
"host_patterns": [r"autoscaling\."],
"credential_scope": "autoscaling",
},
+ "appconfig": {
+ "host_patterns": [r"appconfig\."],
+ "path_prefixes": ["/applications", "/deploymentstrategies", "/deployementstrategies"],
+ "credential_scope": "appconfig",
+ },
+ "appconfigdata": {
+ "host_patterns": [r"appconfigdata\."],
+ "path_prefixes": ["/configurationsessions", "/configuration"],
+ "credential_scope": "appconfigdata",
+ },
}
@@ -247,6 +257,8 @@ def detect_service(method: str, path: str, headers: dict, query_params: dict) ->
"s3files": "s3files",
"rds-data": "rds-data",
"autoscaling": "autoscaling",
+ "appconfig": "appconfig",
+ "appconfigdata": "appconfigdata",
}
if svc_name in scope_map:
return scope_map[svc_name]
diff --git a/ministack/services/appconfig.py b/ministack/services/appconfig.py
new file mode 100644
index 00000000..9e0a294b
--- /dev/null
+++ b/ministack/services/appconfig.py
@@ -0,0 +1,842 @@
+"""
+AppConfig Service Emulator.
+REST/JSON protocol — path-based routing.
+
+Control Plane (appconfig):
+ Applications: CreateApplication, GetApplication, ListApplications,
+ UpdateApplication, DeleteApplication
+ Environments: CreateEnvironment, GetEnvironment, ListEnvironments,
+ UpdateEnvironment, DeleteEnvironment
+ Configuration Profiles: CreateConfigurationProfile, GetConfigurationProfile,
+ ListConfigurationProfiles, UpdateConfigurationProfile,
+ DeleteConfigurationProfile
+ Hosted Configuration Versions: CreateHostedConfigurationVersion,
+ GetHostedConfigurationVersion,
+ ListHostedConfigurationVersions,
+ DeleteHostedConfigurationVersion
+ Deployment Strategies: CreateDeploymentStrategy, GetDeploymentStrategy,
+ ListDeploymentStrategies, UpdateDeploymentStrategy,
+ DeleteDeploymentStrategy
+ Deployments: StartDeployment, GetDeployment, ListDeployments,
+ StopDeployment
+ Tags: TagResource, UntagResource, ListTagsForResource
+
+Data Plane (appconfigdata):
+ StartConfigurationSession, GetLatestConfiguration
+"""
+
+import copy
+import json
+import logging
+import os
+import re
+import time
+import uuid
+
+from ministack.core.persistence import PERSIST_STATE, load_state
+from ministack.core.responses import AccountScopedDict, get_account_id
+
+logger = logging.getLogger("appconfig")
+
+REGION = os.environ.get("MINISTACK_REGION", "us-east-1")
+
+# ---------------------------------------------------------------------------
+# State
+# ---------------------------------------------------------------------------
+
+_applications = AccountScopedDict()
+_environments = AccountScopedDict() # "{app_id}/{env_id}" -> record
+_config_profiles = AccountScopedDict() # "{app_id}/{profile_id}" -> record
+_hosted_versions = AccountScopedDict() # "{app_id}/{profile_id}/{version}" -> record
+_deployment_strategies = AccountScopedDict()
+_deployments = AccountScopedDict() # "{app_id}/{env_id}/{deploy_num}" -> record
+_tags = AccountScopedDict() # arn -> {key: value}
+_sessions = AccountScopedDict() # token -> session record
+
+# ---------------------------------------------------------------------------
+# Persistence
+# ---------------------------------------------------------------------------
+
+
+def get_state():
+ return copy.deepcopy({
+ "applications": _applications,
+ "environments": _environments,
+ "config_profiles": _config_profiles,
+ "hosted_versions": _hosted_versions,
+ "deployment_strategies": _deployment_strategies,
+ "deployments": _deployments,
+ "tags": _tags,
+ })
+
+
+def restore_state(data):
+ _applications.update(data.get("applications", {}))
+ _environments.update(data.get("environments", {}))
+ _config_profiles.update(data.get("config_profiles", {}))
+ _hosted_versions.update(data.get("hosted_versions", {}))
+ _deployment_strategies.update(data.get("deployment_strategies", {}))
+ _deployments.update(data.get("deployments", {}))
+ _tags.update(data.get("tags", {}))
+
+
+_restored = load_state("appconfig")
+if _restored:
+ restore_state(_restored)
+
+# ---------------------------------------------------------------------------
+# Helpers
+# ---------------------------------------------------------------------------
+
+
+def _gen_id():
+ return uuid.uuid4().hex[:7]
+
+
+def _now_iso():
+ return time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime())
+
+
+def _app_arn(app_id):
+ return f"arn:aws:appconfig:{REGION}:{get_account_id()}:application/{app_id}"
+
+
+def _env_arn(app_id, env_id):
+ return f"arn:aws:appconfig:{REGION}:{get_account_id()}:application/{app_id}/environment/{env_id}"
+
+
+def _profile_arn(app_id, profile_id):
+ return f"arn:aws:appconfig:{REGION}:{get_account_id()}:application/{app_id}/configurationprofile/{profile_id}"
+
+
+def _strategy_arn(strategy_id):
+ return f"arn:aws:appconfig:{REGION}:{get_account_id()}:deploymentstrategy/{strategy_id}"
+
+
+def _deployment_arn(app_id, env_id, deploy_num):
+ return (
+ f"arn:aws:appconfig:{REGION}:{get_account_id()}:"
+ f"application/{app_id}/environment/{env_id}/deployment/{deploy_num}"
+ )
+
+
+# ---------------------------------------------------------------------------
+# Applications
+# ---------------------------------------------------------------------------
+
+
+def _create_application(body):
+ name = body.get("Name")
+ if not name:
+ return _error(400, "BadRequestException", "Name is required")
+ app_id = _gen_id()
+ record = {
+ "Id": app_id,
+ "Name": name,
+ "Description": body.get("Description", ""),
+ }
+ _applications[app_id] = record
+ _apply_tags(_app_arn(app_id), body.get("Tags", {}))
+ logger.info("CreateApplication: %s (%s)", name, app_id)
+ return _json(201, record)
+
+
+def _get_application(app_id):
+ app = _applications.get(app_id)
+ if not app:
+ return _error(404, "ResourceNotFoundException", f"Application {app_id} not found")
+ return _json(200, app)
+
+
+def _list_applications(query):
+ max_results = int(query.get("max_results", 50))
+ items = list(_applications.values())
+ return _json(200, {"Items": items[:max_results]})
+
+
+def _update_application(app_id, body):
+ app = _applications.get(app_id)
+ if not app:
+ return _error(404, "ResourceNotFoundException", f"Application {app_id} not found")
+ if "Name" in body:
+ app["Name"] = body["Name"]
+ if "Description" in body:
+ app["Description"] = body["Description"]
+ return _json(200, app)
+
+
+def _delete_application(app_id):
+ if app_id not in _applications:
+ return _error(404, "ResourceNotFoundException", f"Application {app_id} not found")
+ del _applications[app_id]
+ _tags.pop(_app_arn(app_id), None)
+ keys_to_remove = [k for k in _environments if k.startswith(f"{app_id}/")]
+ for k in keys_to_remove:
+ _environments.pop(k, None)
+ keys_to_remove = [k for k in _config_profiles if k.startswith(f"{app_id}/")]
+ for k in keys_to_remove:
+ _config_profiles.pop(k, None)
+ keys_to_remove = [k for k in _hosted_versions if k.startswith(f"{app_id}/")]
+ for k in keys_to_remove:
+ _hosted_versions.pop(k, None)
+ keys_to_remove = [k for k in _deployments if k.startswith(f"{app_id}/")]
+ for k in keys_to_remove:
+ _deployments.pop(k, None)
+ return _json(204, {})
+
+
+# ---------------------------------------------------------------------------
+# Environments
+# ---------------------------------------------------------------------------
+
+
+def _create_environment(app_id, body):
+ if app_id not in _applications:
+ return _error(404, "ResourceNotFoundException", f"Application {app_id} not found")
+ name = body.get("Name")
+ if not name:
+ return _error(400, "BadRequestException", "Name is required")
+ env_id = _gen_id()
+ record = {
+ "ApplicationId": app_id,
+ "Id": env_id,
+ "Name": name,
+ "Description": body.get("Description", ""),
+ "State": "READY_FOR_DEPLOYMENT",
+ "Monitors": body.get("Monitors", []),
+ }
+ _environments[f"{app_id}/{env_id}"] = record
+ _apply_tags(_env_arn(app_id, env_id), body.get("Tags", {}))
+ logger.info("CreateEnvironment: %s/%s (%s)", app_id, name, env_id)
+ return _json(201, record)
+
+
+def _get_environment(app_id, env_id):
+ env = _environments.get(f"{app_id}/{env_id}")
+ if not env:
+ return _error(404, "ResourceNotFoundException", f"Environment {env_id} not found")
+ return _json(200, env)
+
+
+def _list_environments(app_id, query):
+ if app_id not in _applications:
+ return _error(404, "ResourceNotFoundException", f"Application {app_id} not found")
+ max_results = int(query.get("max_results", 50))
+ items = [e for e in _environments.values() if e["ApplicationId"] == app_id]
+ return _json(200, {"Items": items[:max_results]})
+
+
+def _update_environment(app_id, env_id, body):
+ env = _environments.get(f"{app_id}/{env_id}")
+ if not env:
+ return _error(404, "ResourceNotFoundException", f"Environment {env_id} not found")
+ if "Name" in body:
+ env["Name"] = body["Name"]
+ if "Description" in body:
+ env["Description"] = body["Description"]
+ if "Monitors" in body:
+ env["Monitors"] = body["Monitors"]
+ return _json(200, env)
+
+
+def _delete_environment(app_id, env_id):
+ key = f"{app_id}/{env_id}"
+ if key not in _environments:
+ return _error(404, "ResourceNotFoundException", f"Environment {env_id} not found")
+ del _environments[key]
+ _tags.pop(_env_arn(app_id, env_id), None)
+ return _json(204, {})
+
+
+# ---------------------------------------------------------------------------
+# Configuration Profiles
+# ---------------------------------------------------------------------------
+
+
+def _create_configuration_profile(app_id, body):
+ if app_id not in _applications:
+ return _error(404, "ResourceNotFoundException", f"Application {app_id} not found")
+ name = body.get("Name")
+ if not name:
+ return _error(400, "BadRequestException", "Name is required")
+ location_uri = body.get("LocationUri", "hosted")
+ profile_id = _gen_id()
+ record = {
+ "ApplicationId": app_id,
+ "Id": profile_id,
+ "Name": name,
+ "Description": body.get("Description", ""),
+ "LocationUri": location_uri,
+ "RetrievalRoleArn": body.get("RetrievalRoleArn", ""),
+ "Validators": body.get("Validators", []),
+ "Type": body.get("Type", "AWS.Freeform"),
+ }
+ _config_profiles[f"{app_id}/{profile_id}"] = record
+ _apply_tags(_profile_arn(app_id, profile_id), body.get("Tags", {}))
+ logger.info("CreateConfigurationProfile: %s/%s (%s)", app_id, name, profile_id)
+ return _json(201, record)
+
+
+def _get_configuration_profile(app_id, profile_id):
+ profile = _config_profiles.get(f"{app_id}/{profile_id}")
+ if not profile:
+ return _error(404, "ResourceNotFoundException", f"Configuration profile {profile_id} not found")
+ return _json(200, profile)
+
+
+def _list_configuration_profiles(app_id, query):
+ if app_id not in _applications:
+ return _error(404, "ResourceNotFoundException", f"Application {app_id} not found")
+ max_results = int(query.get("max_results", 50))
+ items = [p for p in _config_profiles.values() if p["ApplicationId"] == app_id]
+ return _json(200, {"Items": items[:max_results]})
+
+
+def _update_configuration_profile(app_id, profile_id, body):
+ profile = _config_profiles.get(f"{app_id}/{profile_id}")
+ if not profile:
+ return _error(404, "ResourceNotFoundException", f"Configuration profile {profile_id} not found")
+ for field in ("Name", "Description", "RetrievalRoleArn", "Validators"):
+ if field in body:
+ profile[field] = body[field]
+ return _json(200, profile)
+
+
+def _delete_configuration_profile(app_id, profile_id):
+ key = f"{app_id}/{profile_id}"
+ if key not in _config_profiles:
+ return _error(404, "ResourceNotFoundException", f"Configuration profile {profile_id} not found")
+ del _config_profiles[key]
+ _tags.pop(_profile_arn(app_id, profile_id), None)
+ keys_to_remove = [k for k in _hosted_versions if k.startswith(f"{app_id}/{profile_id}/")]
+ for k in keys_to_remove:
+ _hosted_versions.pop(k, None)
+ return _json(204, {})
+
+
+# ---------------------------------------------------------------------------
+# Hosted Configuration Versions
+# ---------------------------------------------------------------------------
+
+
+def _create_hosted_configuration_version(app_id, profile_id, body, content_type):
+ if f"{app_id}/{profile_id}" not in _config_profiles:
+ return _error(404, "ResourceNotFoundException", f"Configuration profile {profile_id} not found")
+
+ existing = [
+ v for k, v in _hosted_versions.items()
+ if k.startswith(f"{app_id}/{profile_id}/")
+ ]
+ version_number = len(existing) + 1
+
+ record = {
+ "ApplicationId": app_id,
+ "ConfigurationProfileId": profile_id,
+ "VersionNumber": version_number,
+ "ContentType": content_type,
+ "Content": body,
+ "Description": "",
+ }
+ _hosted_versions[f"{app_id}/{profile_id}/{version_number}"] = record
+ logger.info("CreateHostedConfigurationVersion: %s/%s v%d", app_id, profile_id, version_number)
+
+ resp_headers = {
+ "Content-Type": content_type,
+ "Application-Id": app_id,
+ "Configuration-Profile-Id": profile_id,
+ "Version-Number": str(version_number),
+ }
+ return 201, resp_headers, body if isinstance(body, bytes) else body.encode("utf-8")
+
+
+def _get_hosted_configuration_version(app_id, profile_id, version_number):
+ key = f"{app_id}/{profile_id}/{version_number}"
+ record = _hosted_versions.get(key)
+ if not record:
+ return _error(404, "ResourceNotFoundException",
+ f"Hosted configuration version {version_number} not found")
+ content = record["Content"]
+ resp_headers = {
+ "Content-Type": record["ContentType"],
+ "Application-Id": app_id,
+ "Configuration-Profile-Id": profile_id,
+ "Version-Number": str(version_number),
+ }
+ return 200, resp_headers, content if isinstance(content, bytes) else content.encode("utf-8")
+
+
+def _list_hosted_configuration_versions(app_id, profile_id, query):
+ if f"{app_id}/{profile_id}" not in _config_profiles:
+ return _error(404, "ResourceNotFoundException", f"Configuration profile {profile_id} not found")
+ max_results = int(query.get("max_results", 50))
+ items = []
+ for k, v in _hosted_versions.items():
+ if k.startswith(f"{app_id}/{profile_id}/"):
+ items.append({
+ "ApplicationId": app_id,
+ "ConfigurationProfileId": profile_id,
+ "VersionNumber": v["VersionNumber"],
+ "ContentType": v["ContentType"],
+ "Description": v.get("Description", ""),
+ })
+ return _json(200, {"Items": items[:max_results]})
+
+
+def _delete_hosted_configuration_version(app_id, profile_id, version_number):
+ key = f"{app_id}/{profile_id}/{version_number}"
+ if key not in _hosted_versions:
+ return _error(404, "ResourceNotFoundException",
+ f"Hosted configuration version {version_number} not found")
+ del _hosted_versions[key]
+ return _json(204, {})
+
+
+# ---------------------------------------------------------------------------
+# Deployment Strategies
+# ---------------------------------------------------------------------------
+
+
+def _create_deployment_strategy(body):
+ name = body.get("Name")
+ if not name:
+ return _error(400, "BadRequestException", "Name is required")
+ strategy_id = _gen_id()
+ record = {
+ "Id": strategy_id,
+ "Name": name,
+ "Description": body.get("Description", ""),
+ "DeploymentDurationInMinutes": body.get("DeploymentDurationInMinutes", 0),
+ "GrowthType": body.get("GrowthType", "LINEAR"),
+ "GrowthFactor": body.get("GrowthFactor", 100.0),
+ "FinalBakeTimeInMinutes": body.get("FinalBakeTimeInMinutes", 0),
+ "ReplicateTo": body.get("ReplicateTo", "NONE"),
+ }
+ _deployment_strategies[strategy_id] = record
+ _apply_tags(_strategy_arn(strategy_id), body.get("Tags", {}))
+ logger.info("CreateDeploymentStrategy: %s (%s)", name, strategy_id)
+ return _json(201, record)
+
+
+def _get_deployment_strategy(strategy_id):
+ strategy = _deployment_strategies.get(strategy_id)
+ if not strategy:
+ return _error(404, "ResourceNotFoundException", f"Deployment strategy {strategy_id} not found")
+ return _json(200, strategy)
+
+
+def _list_deployment_strategies(query):
+ max_results = int(query.get("max_results", 50))
+ items = list(_deployment_strategies.values())
+ return _json(200, {"Items": items[:max_results]})
+
+
+def _update_deployment_strategy(strategy_id, body):
+ strategy = _deployment_strategies.get(strategy_id)
+ if not strategy:
+ return _error(404, "ResourceNotFoundException", f"Deployment strategy {strategy_id} not found")
+ for field in ("Description", "DeploymentDurationInMinutes", "GrowthType",
+ "GrowthFactor", "FinalBakeTimeInMinutes"):
+ if field in body:
+ strategy[field] = body[field]
+ return _json(200, strategy)
+
+
+def _delete_deployment_strategy(strategy_id):
+ if strategy_id not in _deployment_strategies:
+ return _error(404, "ResourceNotFoundException", f"Deployment strategy {strategy_id} not found")
+ del _deployment_strategies[strategy_id]
+ _tags.pop(_strategy_arn(strategy_id), None)
+ return _json(204, {})
+
+
+# ---------------------------------------------------------------------------
+# Deployments
+# ---------------------------------------------------------------------------
+
+
+def _start_deployment(app_id, env_id, body):
+ if app_id not in _applications:
+ return _error(404, "ResourceNotFoundException", f"Application {app_id} not found")
+ if f"{app_id}/{env_id}" not in _environments:
+ return _error(404, "ResourceNotFoundException", f"Environment {env_id} not found")
+
+ strategy_id = body.get("DeploymentStrategyId", "")
+ profile_id = body.get("ConfigurationProfileId", "")
+ version = body.get("ConfigurationVersion", "")
+
+ if profile_id and f"{app_id}/{profile_id}" not in _config_profiles:
+ return _error(404, "ResourceNotFoundException", f"Configuration profile {profile_id} not found")
+
+ existing = [
+ v for k, v in _deployments.items()
+ if k.startswith(f"{app_id}/{env_id}/")
+ ]
+ deploy_num = len(existing) + 1
+
+ now = _now_iso()
+ record = {
+ "ApplicationId": app_id,
+ "EnvironmentId": env_id,
+ "DeploymentStrategyId": strategy_id,
+ "ConfigurationProfileId": profile_id,
+ "DeploymentNumber": deploy_num,
+ "ConfigurationName": _config_profiles.get(f"{app_id}/{profile_id}", {}).get("Name", ""),
+ "ConfigurationLocationUri": "hosted",
+ "ConfigurationVersion": version,
+ "Description": body.get("Description", ""),
+ "DeploymentDurationInMinutes": 0,
+ "GrowthType": "LINEAR",
+ "GrowthFactor": 100.0,
+ "FinalBakeTimeInMinutes": 0,
+ "State": "COMPLETE",
+ "PercentageComplete": 100.0,
+ "StartedAt": now,
+ "CompletedAt": now,
+ }
+ _deployments[f"{app_id}/{env_id}/{deploy_num}"] = record
+ logger.info("StartDeployment: %s/%s #%d (profile=%s, version=%s)",
+ app_id, env_id, deploy_num, profile_id, version)
+ return _json(201, record)
+
+
+def _get_deployment(app_id, env_id, deploy_num):
+ record = _deployments.get(f"{app_id}/{env_id}/{deploy_num}")
+ if not record:
+ return _error(404, "ResourceNotFoundException", f"Deployment {deploy_num} not found")
+ return _json(200, record)
+
+
+def _list_deployments(app_id, env_id, query):
+ if f"{app_id}/{env_id}" not in _environments:
+ return _error(404, "ResourceNotFoundException", f"Environment {env_id} not found")
+ max_results = int(query.get("max_results", 50))
+ items = []
+ for k, v in _deployments.items():
+ if k.startswith(f"{app_id}/{env_id}/"):
+ items.append({
+ "DeploymentNumber": v["DeploymentNumber"],
+ "ConfigurationName": v.get("ConfigurationName", ""),
+ "ConfigurationVersion": v.get("ConfigurationVersion", ""),
+ "DeploymentDurationInMinutes": v.get("DeploymentDurationInMinutes", 0),
+ "GrowthType": v.get("GrowthType", "LINEAR"),
+ "GrowthFactor": v.get("GrowthFactor", 100.0),
+ "FinalBakeTimeInMinutes": v.get("FinalBakeTimeInMinutes", 0),
+ "State": v.get("State", "COMPLETE"),
+ "PercentageComplete": v.get("PercentageComplete", 100.0),
+ "StartedAt": v.get("StartedAt", ""),
+ "CompletedAt": v.get("CompletedAt", ""),
+ })
+ return _json(200, {"Items": items[:max_results]})
+
+
+def _stop_deployment(app_id, env_id, deploy_num):
+ record = _deployments.get(f"{app_id}/{env_id}/{deploy_num}")
+ if not record:
+ return _error(404, "ResourceNotFoundException", f"Deployment {deploy_num} not found")
+ record["State"] = "ROLLED_BACK"
+ return _json(202, record)
+
+
+# ---------------------------------------------------------------------------
+# Tags
+# ---------------------------------------------------------------------------
+
+
+def _apply_tags(arn, tags_dict):
+ if tags_dict:
+ if arn not in _tags:
+ _tags[arn] = {}
+ _tags[arn].update(tags_dict)
+
+
+def _tag_resource(resource_arn, body):
+ tags_dict = body.get("Tags", {})
+ _apply_tags(resource_arn, tags_dict)
+ return _json(204, {})
+
+
+def _untag_resource(resource_arn, tag_keys):
+ if resource_arn in _tags:
+ for key in tag_keys:
+ _tags[resource_arn].pop(key, None)
+ return _json(204, {})
+
+
+def _list_tags_for_resource(resource_arn):
+ return _json(200, {"Tags": _tags.get(resource_arn, {})})
+
+
+# ---------------------------------------------------------------------------
+# Data Plane — StartConfigurationSession / GetLatestConfiguration
+# ---------------------------------------------------------------------------
+
+
+def _start_configuration_session(body):
+ app_id = body.get("ApplicationIdentifier", "")
+ env_id = body.get("EnvironmentIdentifier", "")
+ profile_id = body.get("ConfigurationProfileIdentifier", "")
+
+ if not app_id or not env_id or not profile_id:
+ return _error(400, "BadRequestException",
+ "ApplicationIdentifier, EnvironmentIdentifier, and "
+ "ConfigurationProfileIdentifier are required")
+
+ token = uuid.uuid4().hex
+ _sessions[token] = {
+ "ApplicationIdentifier": app_id,
+ "EnvironmentIdentifier": env_id,
+ "ConfigurationProfileIdentifier": profile_id,
+ }
+ logger.info("StartConfigurationSession: app=%s env=%s profile=%s", app_id, env_id, profile_id)
+ return _json(201, {"InitialConfigurationToken": token})
+
+
+def _get_latest_configuration(token):
+ session = _sessions.get(token)
+ if not session:
+ return _error(400, "BadRequestException", "Invalid or expired configuration token")
+
+ # Remove the used token
+ del _sessions[token]
+
+ app_id = session["ApplicationIdentifier"]
+ env_id = session["EnvironmentIdentifier"]
+ profile_id = session["ConfigurationProfileIdentifier"]
+
+ # Find the latest completed deployment for this app/env
+ latest_deploy = None
+ for k, v in _deployments.items():
+ if (k.startswith(f"{app_id}/{env_id}/")
+ and v.get("State") == "COMPLETE"
+ and v.get("ConfigurationProfileId") == profile_id):
+ if latest_deploy is None or v["DeploymentNumber"] > latest_deploy["DeploymentNumber"]:
+ latest_deploy = v
+
+ content = b""
+ content_type = "application/octet-stream"
+ if latest_deploy:
+ cfg_version = latest_deploy.get("ConfigurationVersion", "")
+ version_key = f"{app_id}/{profile_id}/{cfg_version}"
+ version_record = _hosted_versions.get(version_key)
+ if version_record:
+ raw = version_record["Content"]
+ content = raw if isinstance(raw, bytes) else raw.encode("utf-8")
+ content_type = version_record.get("ContentType", "application/octet-stream")
+
+ next_token = uuid.uuid4().hex
+ _sessions[next_token] = session.copy()
+
+ resp_headers = {
+ "Content-Type": content_type,
+ "Next-Poll-Configuration-Token": next_token,
+ "Next-Poll-Interval-In-Seconds": "30",
+ }
+ return 200, resp_headers, content
+
+
+# ---------------------------------------------------------------------------
+# Request router
+# ---------------------------------------------------------------------------
+
+
+async def handle_request(method, path, headers, body_bytes, query_params):
+ query = {k: (v[0] if isinstance(v, list) else v) for k, v in query_params.items()}
+
+ # --- Data plane paths ---
+ if path == "/configurationsessions" and method == "POST":
+ try:
+ data = json.loads(body_bytes) if body_bytes else {}
+ except json.JSONDecodeError:
+ return _error(400, "BadRequestException", "Invalid JSON")
+ return await _a(_start_configuration_session(data))
+
+ if path == "/configuration" and method == "GET":
+ token = query.get("configuration_token", "")
+ if not token:
+ return _error(400, "BadRequestException", "configuration_token is required")
+ return await _a(_get_latest_configuration(token))
+
+ # --- Control plane: tags ---
+ m = re.fullmatch(r"/tags/(.+)", path)
+ if m:
+ resource_arn = m.group(1)
+ if method == "POST":
+ try:
+ data = json.loads(body_bytes) if body_bytes else {}
+ except json.JSONDecodeError:
+ return _error(400, "BadRequestException", "Invalid JSON")
+ return await _a(_tag_resource(resource_arn, data))
+ if method == "GET":
+ return await _a(_list_tags_for_resource(resource_arn))
+ if method == "DELETE":
+ tag_keys = query.get("tagKeys", "")
+ keys = [k.strip() for k in tag_keys.split(",") if k.strip()] if tag_keys else []
+ return await _a(_untag_resource(resource_arn, keys))
+
+ # --- Control plane: parse JSON body for non-hosted-version routes ---
+ content_type = headers.get("content-type", "")
+
+ # Hosted configuration versions — body is raw content, not JSON
+ m = re.fullmatch(
+ r"/applications/([^/]+)/configurationprofiles/([^/]+)/hostedconfigurationversions",
+ path,
+ )
+ if m and method == "POST":
+ app_id, profile_id = m.group(1), m.group(2)
+ ct = content_type or "application/octet-stream"
+ return await _a(_create_hosted_configuration_version(app_id, profile_id, body_bytes, ct))
+
+ m = re.fullmatch(
+ r"/applications/([^/]+)/configurationprofiles/([^/]+)/hostedconfigurationversions/(\d+)",
+ path,
+ )
+ if m:
+ app_id, profile_id, ver = m.group(1), m.group(2), int(m.group(3))
+ if method == "GET":
+ return await _a(_get_hosted_configuration_version(app_id, profile_id, ver))
+ if method == "DELETE":
+ return await _a(_delete_hosted_configuration_version(app_id, profile_id, ver))
+
+ m = re.fullmatch(
+ r"/applications/([^/]+)/configurationprofiles/([^/]+)/hostedconfigurationversions",
+ path,
+ )
+ if m and method == "GET":
+ app_id, profile_id = m.group(1), m.group(2)
+ return await _a(_list_hosted_configuration_versions(app_id, profile_id, query))
+
+ # JSON body for remaining routes
+ try:
+ body = json.loads(body_bytes) if body_bytes else {}
+ except json.JSONDecodeError:
+ body = {}
+
+ # --- Applications ---
+ if path == "/applications":
+ if method == "POST":
+ return await _a(_create_application(body))
+ if method == "GET":
+ return await _a(_list_applications(query))
+
+ m = re.fullmatch(r"/applications/([^/]+)", path)
+ if m:
+ app_id = m.group(1)
+ if method == "GET":
+ return await _a(_get_application(app_id))
+ if method == "PATCH":
+ return await _a(_update_application(app_id, body))
+ if method == "DELETE":
+ return await _a(_delete_application(app_id))
+
+ # --- Deployments (must be checked before environments) ---
+ m = re.fullmatch(r"/applications/([^/]+)/environments/([^/]+)/deployments", path)
+ if m:
+ app_id, env_id = m.group(1), m.group(2)
+ if method == "POST":
+ return await _a(_start_deployment(app_id, env_id, body))
+ if method == "GET":
+ return await _a(_list_deployments(app_id, env_id, query))
+
+ m = re.fullmatch(r"/applications/([^/]+)/environments/([^/]+)/deployments/(\d+)", path)
+ if m:
+ app_id, env_id, deploy_num = m.group(1), m.group(2), int(m.group(3))
+ if method == "GET":
+ return await _a(_get_deployment(app_id, env_id, deploy_num))
+ if method == "DELETE":
+ return await _a(_stop_deployment(app_id, env_id, deploy_num))
+
+ # --- Environments ---
+ m = re.fullmatch(r"/applications/([^/]+)/environments", path)
+ if m:
+ app_id = m.group(1)
+ if method == "POST":
+ return await _a(_create_environment(app_id, body))
+ if method == "GET":
+ return await _a(_list_environments(app_id, query))
+
+ m = re.fullmatch(r"/applications/([^/]+)/environments/([^/]+)", path)
+ if m:
+ app_id, env_id = m.group(1), m.group(2)
+ if method == "GET":
+ return await _a(_get_environment(app_id, env_id))
+ if method == "PATCH":
+ return await _a(_update_environment(app_id, env_id, body))
+ if method == "DELETE":
+ return await _a(_delete_environment(app_id, env_id))
+
+ # --- Configuration Profiles ---
+ m = re.fullmatch(r"/applications/([^/]+)/configurationprofiles", path)
+ if m:
+ app_id = m.group(1)
+ if method == "POST":
+ return await _a(_create_configuration_profile(app_id, body))
+ if method == "GET":
+ return await _a(_list_configuration_profiles(app_id, query))
+
+ m = re.fullmatch(r"/applications/([^/]+)/configurationprofiles/([^/]+)", path)
+ if m:
+ app_id, profile_id = m.group(1), m.group(2)
+ if method == "GET":
+ return await _a(_get_configuration_profile(app_id, profile_id))
+ if method == "PATCH":
+ return await _a(_update_configuration_profile(app_id, profile_id, body))
+ if method == "DELETE":
+ return await _a(_delete_configuration_profile(app_id, profile_id))
+
+ # --- Deployment Strategies ---
+ # botocore's model uses the misspelled path "/deployementstrategies" for
+ # DeleteDeploymentStrategy (and possibly others), so accept both spellings.
+ if path in ("/deploymentstrategies", "/deployementstrategies"):
+ if method == "POST":
+ return await _a(_create_deployment_strategy(body))
+ if method == "GET":
+ return await _a(_list_deployment_strategies(query))
+
+ m = re.fullmatch(r"/deploy(?:e?)mentstrategies/([^/]+)", path)
+ if m:
+ strategy_id = m.group(1)
+ if method == "GET":
+ return await _a(_get_deployment_strategy(strategy_id))
+ if method == "PATCH":
+ return await _a(_update_deployment_strategy(strategy_id, body))
+ if method == "DELETE":
+ return await _a(_delete_deployment_strategy(strategy_id))
+
+ return _error(400, "BadRequestException", f"Unknown AppConfig path: {method} {path}")
+
+
+async def _a(result):
+ return result
+
+
+# ---------------------------------------------------------------------------
+# Response helpers
+# ---------------------------------------------------------------------------
+
+
+def _json(status, data):
+ if status == 204:
+ return status, {}, b""
+ body = json.dumps(data).encode("utf-8")
+ return status, {"Content-Type": "application/json"}, body
+
+
+def _error(status, code, message):
+ body = json.dumps({"Message": message, "Code": code}).encode("utf-8")
+ return status, {"Content-Type": "application/json", "x-amzn-errortype": code}, body
+
+
+# ---------------------------------------------------------------------------
+# Reset
+# ---------------------------------------------------------------------------
+
+
+def reset():
+ _applications.clear()
+ _environments.clear()
+ _config_profiles.clear()
+ _hosted_versions.clear()
+ _deployment_strategies.clear()
+ _deployments.clear()
+ _tags.clear()
+ _sessions.clear()
diff --git a/tests/conftest.py b/tests/conftest.py
index 50ed2e19..3014bd05 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -254,6 +254,14 @@ def cloudfront():
def rds_data():
return make_client("rds-data")
[email protected](scope="session")
+def appconfig_client():
+ return make_client("appconfig")
+
[email protected](scope="session")
+def appconfigdata_client():
+ return make_client("appconfigdata")
+
@pytest.fixture(scope="session")
def sd():
"""SD client for DiscoverInstances — forces same endpoint (boto3 normally prefixes data-)."""
diff --git a/tests/test_appconfig.py b/tests/test_appconfig.py
new file mode 100644
index 00000000..7fc7ffce
--- /dev/null
+++ b/tests/test_appconfig.py
@@ -0,0 +1,556 @@
+import json
+
+import pytest
+from botocore.exceptions import ClientError
+
+# ---------------------------------------------------------------------------
+# Applications
+# ---------------------------------------------------------------------------
+
+
+def test_appconfig_create_application(appconfig_client):
+ resp = appconfig_client.create_application(Name="my-app", Description="Test app")
+ assert resp["Id"]
+ assert resp["Name"] == "my-app"
+ assert resp["Description"] == "Test app"
+
+
+def test_appconfig_get_application(appconfig_client):
+ created = appconfig_client.create_application(Name="get-app")
+ app_id = created["Id"]
+ resp = appconfig_client.get_application(ApplicationId=app_id)
+ assert resp["Id"] == app_id
+ assert resp["Name"] == "get-app"
+
+
+def test_appconfig_list_applications(appconfig_client):
+ appconfig_client.create_application(Name="list-app-1")
+ appconfig_client.create_application(Name="list-app-2")
+ resp = appconfig_client.list_applications()
+ names = [a["Name"] for a in resp["Items"]]
+ assert "list-app-1" in names
+ assert "list-app-2" in names
+
+
+def test_appconfig_update_application(appconfig_client):
+ created = appconfig_client.create_application(Name="update-app")
+ app_id = created["Id"]
+ resp = appconfig_client.update_application(ApplicationId=app_id, Name="renamed-app", Description="new desc")
+ assert resp["Name"] == "renamed-app"
+ assert resp["Description"] == "new desc"
+
+
+def test_appconfig_delete_application(appconfig_client):
+ created = appconfig_client.create_application(Name="delete-app")
+ app_id = created["Id"]
+ appconfig_client.delete_application(ApplicationId=app_id)
+ with pytest.raises(ClientError) as exc:
+ appconfig_client.get_application(ApplicationId=app_id)
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+
+
+# ---------------------------------------------------------------------------
+# Environments
+# ---------------------------------------------------------------------------
+
+
+def test_appconfig_create_environment(appconfig_client):
+ app = appconfig_client.create_application(Name="env-app")
+ resp = appconfig_client.create_environment(
+ ApplicationId=app["Id"],
+ Name="dev",
+ Description="Development",
+ )
+ assert resp["Id"]
+ assert resp["Name"] == "dev"
+ assert resp["State"] == "READY_FOR_DEPLOYMENT"
+
+
+def test_appconfig_get_environment(appconfig_client):
+ app = appconfig_client.create_application(Name="env-get-app")
+ env = appconfig_client.create_environment(ApplicationId=app["Id"], Name="staging")
+ resp = appconfig_client.get_environment(ApplicationId=app["Id"], EnvironmentId=env["Id"])
+ assert resp["Name"] == "staging"
+
+
+def test_appconfig_list_environments(appconfig_client):
+ app = appconfig_client.create_application(Name="env-list-app")
+ appconfig_client.create_environment(ApplicationId=app["Id"], Name="env-a")
+ appconfig_client.create_environment(ApplicationId=app["Id"], Name="env-b")
+ resp = appconfig_client.list_environments(ApplicationId=app["Id"])
+ names = [e["Name"] for e in resp["Items"]]
+ assert "env-a" in names
+ assert "env-b" in names
+
+
+def test_appconfig_update_environment(appconfig_client):
+ app = appconfig_client.create_application(Name="env-update-app")
+ env = appconfig_client.create_environment(ApplicationId=app["Id"], Name="old-name")
+ resp = appconfig_client.update_environment(
+ ApplicationId=app["Id"],
+ EnvironmentId=env["Id"],
+ Name="new-name",
+ Description="updated",
+ )
+ assert resp["Name"] == "new-name"
+ assert resp["Description"] == "updated"
+
+
+def test_appconfig_delete_environment(appconfig_client):
+ app = appconfig_client.create_application(Name="env-delete-app")
+ env = appconfig_client.create_environment(ApplicationId=app["Id"], Name="to-delete")
+ appconfig_client.delete_environment(ApplicationId=app["Id"], EnvironmentId=env["Id"])
+ with pytest.raises(ClientError) as exc:
+ appconfig_client.get_environment(ApplicationId=app["Id"], EnvironmentId=env["Id"])
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+
+
+# ---------------------------------------------------------------------------
+# Configuration Profiles
+# ---------------------------------------------------------------------------
+
+
+def test_appconfig_create_configuration_profile(appconfig_client):
+ app = appconfig_client.create_application(Name="profile-app")
+ resp = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"],
+ Name="my-config",
+ LocationUri="hosted",
+ Type="AWS.Freeform",
+ )
+ assert resp["Id"]
+ assert resp["Name"] == "my-config"
+ assert resp["LocationUri"] == "hosted"
+
+
+def test_appconfig_get_configuration_profile(appconfig_client):
+ app = appconfig_client.create_application(Name="profile-get-app")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="get-profile", LocationUri="hosted",
+ )
+ resp = appconfig_client.get_configuration_profile(
+ ApplicationId=app["Id"], ConfigurationProfileId=profile["Id"],
+ )
+ assert resp["Name"] == "get-profile"
+
+
+def test_appconfig_list_configuration_profiles(appconfig_client):
+ app = appconfig_client.create_application(Name="profile-list-app")
+ appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="profile-1", LocationUri="hosted",
+ )
+ appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="profile-2", LocationUri="hosted",
+ )
+ resp = appconfig_client.list_configuration_profiles(ApplicationId=app["Id"])
+ names = [p["Name"] for p in resp["Items"]]
+ assert "profile-1" in names
+ assert "profile-2" in names
+
+
+def test_appconfig_update_configuration_profile(appconfig_client):
+ app = appconfig_client.create_application(Name="profile-update-app")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="old-profile", LocationUri="hosted",
+ )
+ resp = appconfig_client.update_configuration_profile(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Name="new-profile",
+ Description="updated desc",
+ )
+ assert resp["Name"] == "new-profile"
+ assert resp["Description"] == "updated desc"
+
+
+def test_appconfig_delete_configuration_profile(appconfig_client):
+ app = appconfig_client.create_application(Name="profile-delete-app")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="to-delete", LocationUri="hosted",
+ )
+ appconfig_client.delete_configuration_profile(
+ ApplicationId=app["Id"], ConfigurationProfileId=profile["Id"],
+ )
+ with pytest.raises(ClientError) as exc:
+ appconfig_client.get_configuration_profile(
+ ApplicationId=app["Id"], ConfigurationProfileId=profile["Id"],
+ )
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+
+
+# ---------------------------------------------------------------------------
+# Hosted Configuration Versions
+# ---------------------------------------------------------------------------
+
+
+def test_appconfig_create_hosted_configuration_version(appconfig_client):
+ app = appconfig_client.create_application(Name="hcv-app")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="hcv-profile", LocationUri="hosted",
+ )
+ content = json.dumps({"feature_flag": True}).encode("utf-8")
+ resp = appconfig_client.create_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Content=content,
+ ContentType="application/json",
+ )
+ assert resp["VersionNumber"] == 1
+ assert resp["ContentType"] == "application/json"
+ assert resp["Content"].read() == content
+
+
+def test_appconfig_get_hosted_configuration_version(appconfig_client):
+ app = appconfig_client.create_application(Name="hcv-get-app")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="hcv-get-profile", LocationUri="hosted",
+ )
+ content = b'{"key":"value"}'
+ appconfig_client.create_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Content=content,
+ ContentType="application/json",
+ )
+ resp = appconfig_client.get_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ VersionNumber=1,
+ )
+ assert resp["Content"].read() == content
+
+
+def test_appconfig_list_hosted_configuration_versions(appconfig_client):
+ app = appconfig_client.create_application(Name="hcv-list-app")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="hcv-list-profile", LocationUri="hosted",
+ )
+ appconfig_client.create_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Content=b"v1",
+ ContentType="text/plain",
+ )
+ appconfig_client.create_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Content=b"v2",
+ ContentType="text/plain",
+ )
+ resp = appconfig_client.list_hosted_configuration_versions(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ )
+ assert len(resp["Items"]) == 2
+ versions = [i["VersionNumber"] for i in resp["Items"]]
+ assert 1 in versions
+ assert 2 in versions
+
+
+def test_appconfig_delete_hosted_configuration_version(appconfig_client):
+ app = appconfig_client.create_application(Name="hcv-del-app")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="hcv-del-profile", LocationUri="hosted",
+ )
+ appconfig_client.create_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Content=b"data",
+ ContentType="text/plain",
+ )
+ appconfig_client.delete_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ VersionNumber=1,
+ )
+ with pytest.raises(ClientError) as exc:
+ appconfig_client.get_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ VersionNumber=1,
+ )
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+
+
+# ---------------------------------------------------------------------------
+# Deployment Strategies
+# ---------------------------------------------------------------------------
+
+
+def test_appconfig_create_deployment_strategy(appconfig_client):
+ resp = appconfig_client.create_deployment_strategy(
+ Name="quick-deploy",
+ DeploymentDurationInMinutes=0,
+ GrowthFactor=100.0,
+ ReplicateTo="NONE",
+ )
+ assert resp["Id"]
+ assert resp["Name"] == "quick-deploy"
+ assert resp["GrowthFactor"] == 100.0
+
+
+def test_appconfig_get_deployment_strategy(appconfig_client):
+ created = appconfig_client.create_deployment_strategy(
+ Name="get-strategy",
+ DeploymentDurationInMinutes=10,
+ GrowthFactor=50.0,
+ ReplicateTo="NONE",
+ )
+ resp = appconfig_client.get_deployment_strategy(DeploymentStrategyId=created["Id"])
+ assert resp["Name"] == "get-strategy"
+ assert resp["DeploymentDurationInMinutes"] == 10
+
+
+def test_appconfig_list_deployment_strategies(appconfig_client):
+ appconfig_client.create_deployment_strategy(
+ Name="list-strat-1", DeploymentDurationInMinutes=0, GrowthFactor=100.0, ReplicateTo="NONE",
+ )
+ resp = appconfig_client.list_deployment_strategies()
+ assert len(resp["Items"]) >= 1
+
+
+def test_appconfig_update_deployment_strategy(appconfig_client):
+ created = appconfig_client.create_deployment_strategy(
+ Name="upd-strategy", DeploymentDurationInMinutes=5, GrowthFactor=50.0, ReplicateTo="NONE",
+ )
+ resp = appconfig_client.update_deployment_strategy(
+ DeploymentStrategyId=created["Id"],
+ Description="updated",
+ GrowthFactor=75.0,
+ )
+ assert resp["Description"] == "updated"
+ assert resp["GrowthFactor"] == 75.0
+
+
+def test_appconfig_delete_deployment_strategy(appconfig_client):
+ created = appconfig_client.create_deployment_strategy(
+ Name="del-strategy", DeploymentDurationInMinutes=0, GrowthFactor=100.0, ReplicateTo="NONE",
+ )
+ appconfig_client.delete_deployment_strategy(DeploymentStrategyId=created["Id"])
+ with pytest.raises(ClientError) as exc:
+ appconfig_client.get_deployment_strategy(DeploymentStrategyId=created["Id"])
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+
+
+# ---------------------------------------------------------------------------
+# Deployments
+# ---------------------------------------------------------------------------
+
+
+def test_appconfig_start_deployment(appconfig_client):
+ app = appconfig_client.create_application(Name="deploy-app")
+ env = appconfig_client.create_environment(ApplicationId=app["Id"], Name="prod")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="deploy-profile", LocationUri="hosted",
+ )
+ appconfig_client.create_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Content=b'{"enabled":true}',
+ ContentType="application/json",
+ )
+ strategy = appconfig_client.create_deployment_strategy(
+ Name="instant", DeploymentDurationInMinutes=0, GrowthFactor=100.0, ReplicateTo="NONE",
+ )
+ resp = appconfig_client.start_deployment(
+ ApplicationId=app["Id"],
+ EnvironmentId=env["Id"],
+ DeploymentStrategyId=strategy["Id"],
+ ConfigurationProfileId=profile["Id"],
+ ConfigurationVersion="1",
+ )
+ assert resp["DeploymentNumber"] == 1
+ assert resp["State"] == "COMPLETE"
+ assert resp["PercentageComplete"] == 100.0
+
+
+def test_appconfig_get_deployment(appconfig_client):
+ app = appconfig_client.create_application(Name="deploy-get-app")
+ env = appconfig_client.create_environment(ApplicationId=app["Id"], Name="staging")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="deploy-get-profile", LocationUri="hosted",
+ )
+ appconfig_client.create_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Content=b"config",
+ ContentType="text/plain",
+ )
+ strategy = appconfig_client.create_deployment_strategy(
+ Name="get-strat", DeploymentDurationInMinutes=0, GrowthFactor=100.0, ReplicateTo="NONE",
+ )
+ deploy = appconfig_client.start_deployment(
+ ApplicationId=app["Id"],
+ EnvironmentId=env["Id"],
+ DeploymentStrategyId=strategy["Id"],
+ ConfigurationProfileId=profile["Id"],
+ ConfigurationVersion="1",
+ )
+ resp = appconfig_client.get_deployment(
+ ApplicationId=app["Id"],
+ EnvironmentId=env["Id"],
+ DeploymentNumber=deploy["DeploymentNumber"],
+ )
+ assert resp["State"] == "COMPLETE"
+
+
+def test_appconfig_list_deployments(appconfig_client):
+ app = appconfig_client.create_application(Name="deploy-list-app")
+ env = appconfig_client.create_environment(ApplicationId=app["Id"], Name="dev")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="deploy-list-profile", LocationUri="hosted",
+ )
+ appconfig_client.create_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Content=b"c1",
+ ContentType="text/plain",
+ )
+ strategy = appconfig_client.create_deployment_strategy(
+ Name="list-strat", DeploymentDurationInMinutes=0, GrowthFactor=100.0, ReplicateTo="NONE",
+ )
+ appconfig_client.start_deployment(
+ ApplicationId=app["Id"],
+ EnvironmentId=env["Id"],
+ DeploymentStrategyId=strategy["Id"],
+ ConfigurationProfileId=profile["Id"],
+ ConfigurationVersion="1",
+ )
+ resp = appconfig_client.list_deployments(
+ ApplicationId=app["Id"],
+ EnvironmentId=env["Id"],
+ )
+ assert len(resp["Items"]) >= 1
+
+
+def test_appconfig_stop_deployment(appconfig_client):
+ app = appconfig_client.create_application(Name="deploy-stop-app")
+ env = appconfig_client.create_environment(ApplicationId=app["Id"], Name="qa")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="deploy-stop-profile", LocationUri="hosted",
+ )
+ appconfig_client.create_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Content=b"data",
+ ContentType="text/plain",
+ )
+ strategy = appconfig_client.create_deployment_strategy(
+ Name="stop-strat", DeploymentDurationInMinutes=0, GrowthFactor=100.0, ReplicateTo="NONE",
+ )
+ deploy = appconfig_client.start_deployment(
+ ApplicationId=app["Id"],
+ EnvironmentId=env["Id"],
+ DeploymentStrategyId=strategy["Id"],
+ ConfigurationProfileId=profile["Id"],
+ ConfigurationVersion="1",
+ )
+ resp = appconfig_client.stop_deployment(
+ ApplicationId=app["Id"],
+ EnvironmentId=env["Id"],
+ DeploymentNumber=deploy["DeploymentNumber"],
+ )
+ assert resp["State"] == "ROLLED_BACK"
+
+
+# ---------------------------------------------------------------------------
+# Tags
+# ---------------------------------------------------------------------------
+
+
+def test_appconfig_tag_resource(appconfig_client):
+ app = appconfig_client.create_application(Name="tag-app", Tags={"env": "test"})
+ app_arn = f"arn:aws:appconfig:us-east-1:000000000000:application/{app['Id']}"
+ resp = appconfig_client.list_tags_for_resource(ResourceArn=app_arn)
+ assert resp["Tags"]["env"] == "test"
+
+ appconfig_client.tag_resource(ResourceArn=app_arn, Tags={"team": "platform"})
+ resp = appconfig_client.list_tags_for_resource(ResourceArn=app_arn)
+ assert resp["Tags"]["team"] == "platform"
+ assert resp["Tags"]["env"] == "test"
+
+ appconfig_client.untag_resource(ResourceArn=app_arn, TagKeys=["env"])
+ resp = appconfig_client.list_tags_for_resource(ResourceArn=app_arn)
+ assert "env" not in resp["Tags"]
+ assert resp["Tags"]["team"] == "platform"
+
+
+# ---------------------------------------------------------------------------
+# Data Plane — full end-to-end workflow
+# ---------------------------------------------------------------------------
+
+
+def test_appconfig_data_plane_e2e(appconfig_client, appconfigdata_client):
+ app = appconfig_client.create_application(Name="data-plane-app")
+ env = appconfig_client.create_environment(ApplicationId=app["Id"], Name="live")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="data-profile", LocationUri="hosted",
+ )
+ config_content = json.dumps({"feature_x": True, "max_retries": 3}).encode("utf-8")
+ appconfig_client.create_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Content=config_content,
+ ContentType="application/json",
+ )
+ strategy = appconfig_client.create_deployment_strategy(
+ Name="e2e-strategy",
+ DeploymentDurationInMinutes=0,
+ GrowthFactor=100.0,
+ ReplicateTo="NONE",
+ )
+ appconfig_client.start_deployment(
+ ApplicationId=app["Id"],
+ EnvironmentId=env["Id"],
+ DeploymentStrategyId=strategy["Id"],
+ ConfigurationProfileId=profile["Id"],
+ ConfigurationVersion="1",
+ )
+
+ session = appconfigdata_client.start_configuration_session(
+ ApplicationIdentifier=app["Id"],
+ EnvironmentIdentifier=env["Id"],
+ ConfigurationProfileIdentifier=profile["Id"],
+ )
+ token = session["InitialConfigurationToken"]
+ assert token
+
+ latest = appconfigdata_client.get_latest_configuration(ConfigurationToken=token)
+ body = latest["Configuration"].read()
+ assert json.loads(body) == {"feature_x": True, "max_retries": 3}
+ assert latest["ContentType"] == "application/json"
+ assert latest["NextPollConfigurationToken"]
+
+ # Second call with new token should also work
+ latest2 = appconfigdata_client.get_latest_configuration(
+ ConfigurationToken=latest["NextPollConfigurationToken"],
+ )
+ assert latest2["NextPollConfigurationToken"]
+
+
+# ---------------------------------------------------------------------------
+# Error cases
+# ---------------------------------------------------------------------------
+
+
+def test_appconfig_get_nonexistent_application(appconfig_client):
+ with pytest.raises(ClientError) as exc:
+ appconfig_client.get_application(ApplicationId="nonexistent")
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+
+
+def test_appconfig_get_nonexistent_environment(appconfig_client):
+ app = appconfig_client.create_application(Name="err-env-app")
+ with pytest.raises(ClientError) as exc:
+ appconfig_client.get_environment(ApplicationId=app["Id"], EnvironmentId="nonexistent")
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+
+
+def test_appconfig_get_nonexistent_deployment(appconfig_client):
+ app = appconfig_client.create_application(Name="err-deploy-app")
+ env = appconfig_client.create_environment(ApplicationId=app["Id"], Name="err-env")
+ with pytest.raises(ClientError) as exc:
+ appconfig_client.get_deployment(
+ ApplicationId=app["Id"], EnvironmentId=env["Id"], DeploymentNumber=999,
+ )
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"