Skip to content

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

fix(cloudformation): keep AppSync data source and resolver configuration (#2182)

iot-rocketfcf83ca3155d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0196427c..14c604e2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]
### Fixed
+- **CloudFormation — AppSync data sources and resolvers keep their configuration** — `AWS::AppSync::DataSource` dropped `Description`, `HttpConfig` and `EventBridgeConfig` and stored `DynamoDBConfig` and `LambdaConfig` in the template's PascalCase, and `AWS::AppSync::Resolver` dropped `Kind`, `Runtime`, `Code`, `PipelineConfig` and `MaxBatchSize`, so a DynamoDB resolver from a stack answered `null` and an `APPSYNC_JS` resolver never ran; both now go through `CreateDataSource` and `CreateResolver` and read back as on AWS, and a new data source `Name` or resolver `TypeName` or `FieldName` is reported as a replacement. `GetDataSource` and `GetResolver` leave out a description, service role or mapping template that was never set, a DynamoDB data source reports `useCallerCredentials` and `versioned`, an EventBridge one keeps `eventBridgeConfig`, and a resolver reports `maxBatchSize`. Contributed by @iot-rocket.
- **CloudFormation — `AWS::AutoScaling::LifecycleHook` updates** — a stack update ran the create again, so a member dropped from the template went back to its default and a hook with a generated name moved to another group stayed on the old group too; the hook now updates in place and keeps a dropped member, and an `AutoScalingGroupName` or `LifecycleHookName` change replaces it. `NotificationMetadata` is stored and returned by `DescribeLifecycleHooks`, and a group deleted by its stack takes its lifecycle hooks along. Contributed by @iot-rocket.
- **IoT — mTLS refusals close without a CONNACK under `AUTH=true`** — with `AUTH=true` the mTLS listener closes the connection of an unknown, inactive, revoked or doubly-registered client certificate after its CONNECT without sending a CONNACK, as AWS does on MQTT 3.1.1 and 5; without `AUTH` it still answers a "not authorized" CONNACK, and the log names the reason either way. Contributed by @iot-rocket.
- **IoT — `AttachPolicy` to a target that does not exist** — `AttachPolicy` and `AttachPrincipalPolicy` accepted any target string; they now answer `ResourceNotFoundException` for an unknown certificate or thing group, `InvalidRequestException` for anything else that is not a certificate, a thing group (`AttachPolicy` only) or a Cognito identity id, and `AccessDeniedException` for another account's certificate, which also fails an `AWS::IoT::PolicyPrincipalAttachment` naming such a principal. Contributed by @iot-rocket.
diff --git a/ministack/services/appsync.py b/ministack/services/appsync.py
index dcb9ed50..5c651901 100644
--- a/ministack/services/appsync.py
+++ b/ministack/services/appsync.py
@@ -324,8 +324,6 @@ def _create_data_source(api_id, body):
name = body.get("name", "")
ds_type = body.get("type", "NONE")
- description = body.get("description", "")
- service_role_arn = body.get("serviceRoleArn", "")
arn = f"{_apis[api_id]['arn']}/datasources/{name}"
@@ -333,14 +331,17 @@ def _create_data_source(api_id, body):
"dataSourceArn": arn,
"name": name,
"type": ds_type,
- "description": description,
- "serviceRoleArn": service_role_arn,
"createdAt": _now(),
"lastUpdatedAt": _now(),
}
+ # Members the caller left out are absent from the data source.
+ for member in ("description", "serviceRoleArn", "metricsConfig"):
+ if body.get(member):
+ record[member] = body[member]
if ds_type == "AMAZON_DYNAMODB":
- record["dynamodbConfig"] = body.get("dynamodbConfig", {})
+ record["dynamodbConfig"] = {"useCallerCredentials": False, "versioned": False,
+ **body.get("dynamodbConfig", {})}
elif ds_type == "AWS_LAMBDA":
record["lambdaConfig"] = body.get("lambdaConfig", {})
elif ds_type == "AMAZON_ELASTICSEARCH" or ds_type == "AMAZON_OPENSEARCH_SERVICE":
@@ -349,6 +350,8 @@ def _create_data_source(api_id, body):
record["httpConfig"] = body.get("httpConfig", {})
elif ds_type == "RELATIONAL_DATABASE":
record["relationalDatabaseConfig"] = body.get("relationalDatabaseConfig", {})
+ elif ds_type == "AMAZON_EVENTBRIDGE":
+ record["eventBridgeConfig"] = body.get("eventBridgeConfig", {})
_data_sources.setdefault(api_id, {})[name] = record
return _json(200, {"dataSource": record})
@@ -410,12 +413,15 @@ def _create_resolver(api_id, type_name, body):
"fieldName": field_name,
"dataSourceName": data_source_name,
"resolverArn": arn,
- "requestMappingTemplate": request_template,
- "responseMappingTemplate": response_template,
"kind": kind,
+ "maxBatchSize": body.get("maxBatchSize", 0),
"createdAt": _now(),
"lastUpdatedAt": _now(),
}
+ if request_template:
+ record["requestMappingTemplate"] = request_template
+ if response_template:
+ record["responseMappingTemplate"] = response_template
if pipeline_config:
record["pipelineConfig"] = pipeline_config
if caching_config:
@@ -424,6 +430,9 @@ def _create_resolver(api_id, type_name, body):
record["runtime"] = runtime
if code:
record["code"] = code
+ for optional in ("syncConfig", "metricsConfig"):
+ if body.get(optional) is not None:
+ record[optional] = body[optional]
_resolvers.setdefault(api_id, {}).setdefault(type_name, {})[field_name] = record
return _json(200, {"resolver": record})
diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.py
index 873458ae..7f80a5ff 100644
--- a/ministack/services/cloudformation/provisioners.py
+++ b/ministack/services/cloudformation/provisioners.py
@@ -6323,22 +6323,28 @@ def _appsync_api_delete(physical_id, props):
_appsync._delete_graphql_api(physical_id)
+# The DataSource properties and the CreateDataSource members they become.
+_APPSYNC_DS_MEMBERS = {
+ "Description": "description", "ServiceRoleArn": "serviceRoleArn",
+ "DynamoDBConfig": "dynamodbConfig", "LambdaConfig": "lambdaConfig",
+ "ElasticsearchConfig": "elasticsearchConfig", "OpenSearchServiceConfig": "openSearchServiceConfig",
+ "HttpConfig": "httpConfig", "RelationalDatabaseConfig": "relationalDatabaseConfig",
+ "EventBridgeConfig": "eventBridgeConfig", "MetricsConfig": "metricsConfig",
+}
+
+
def _appsync_ds_create(logical_id, props, stack_name):
api_id = props.get("ApiId", "")
name = props.get("Name") or logical_id
- ds_type = props.get("Type", "NONE")
- body = {"name": name, "type": ds_type}
- if props.get("DynamoDBConfig"):
- body["dynamodbConfig"] = props["DynamoDBConfig"]
- if props.get("LambdaConfig"):
- body["lambdaConfig"] = props["LambdaConfig"]
- if props.get("ServiceRoleArn"):
- body["serviceRoleArn"] = props["ServiceRoleArn"]
- _appsync._data_sources.setdefault(api_id, {})[name] = {
- "name": name, "type": ds_type, **body,
- "dataSourceArn": f"arn:aws:appsync:{get_region()}:{get_account_id()}:apis/{api_id}/datasources/{name}",
- }
- return f"{api_id}/{name}", {"Name": name, "DataSourceArn": f"arn:aws:appsync:{get_region()}:{get_account_id()}:apis/{api_id}/datasources/{name}"}
+ body = {"name": name, "type": props.get("Type", "NONE")}
+ for prop, member in _APPSYNC_DS_MEMBERS.items():
+ if props.get(prop) not in (None, ""):
+ body[member] = _pascal_to_camel(props[prop])
+ resp = _appsync._create_data_source(api_id, body)
+ if resp[0] >= 400:
+ raise ValueError(f"AWS::AppSync::DataSource create failed: {resp[2]!r}")
+ arn = _appsync._data_sources[api_id][name]["dataSourceArn"]
+ return f"{api_id}/{name}", {"Name": name, "DataSourceArn": arn}
def _appsync_ds_delete(physical_id, props):
@@ -6381,22 +6387,29 @@ def _appsync_function_delete(physical_id, props):
pass
+# The Resolver properties that become CreateResolver members.
+_APPSYNC_RESOLVER_MEMBERS = (
+ "DataSourceName", "RequestMappingTemplate", "ResponseMappingTemplate", "Kind",
+ "PipelineConfig", "CachingConfig", "SyncConfig", "MaxBatchSize", "Runtime", "Code",
+ "MetricsConfig",
+)
+
+
def _appsync_resolver_create(logical_id, props, stack_name):
api_id = props.get("ApiId", "")
type_name = props.get("TypeName", "Query")
field_name = props.get("FieldName", logical_id)
- ds_name = props.get("DataSourceName", "")
- resolver = {
- "typeName": type_name, "fieldName": field_name,
- "dataSourceName": ds_name,
- "resolverArn": f"arn:aws:appsync:{get_region()}:{get_account_id()}:apis/{api_id}/types/{type_name}/resolvers/{field_name}",
- }
- if props.get("RequestMappingTemplate"):
- resolver["requestMappingTemplate"] = props["RequestMappingTemplate"]
- if props.get("ResponseMappingTemplate"):
- resolver["responseMappingTemplate"] = props["ResponseMappingTemplate"]
- _appsync._resolvers.setdefault(api_id, {}).setdefault(type_name, {})[field_name] = resolver
- return f"{api_id}/{type_name}/{field_name}", {"ResolverArn": resolver["resolverArn"]}
+ body = {"fieldName": field_name}
+ for prop in _APPSYNC_RESOLVER_MEMBERS:
+ if props.get(prop) not in (None, ""):
+ body[prop[:1].lower() + prop[1:]] = _pascal_to_camel(props[prop])
+ if "maxBatchSize" in body:
+ body["maxBatchSize"] = int(body["maxBatchSize"])
+ resp = _appsync._create_resolver(api_id, type_name, body)
+ if resp[0] >= 400:
+ raise ValueError(f"AWS::AppSync::Resolver create failed: {resp[2]!r}")
+ arn = _appsync._resolvers[api_id][type_name][field_name]["resolverArn"]
+ return f"{api_id}/{type_name}/{field_name}", {"ResolverArn": arn}
def _appsync_resolver_delete(physical_id, props):
@@ -14218,6 +14231,9 @@ _REPLACING_PROPERTIES: dict[str, tuple[str, ...]] = {
"AWS::DocDB::DBClusterParameterGroup": ("Description", "Family", "Name"),
"AWS::DynamoDB::Table": ("TableName", "ImportSourceSpecification"),
"AWS::StepFunctions::StateMachine": ("StateMachineName", "StateMachineType"),
+ "AWS::AppSync::DataSource": ("ApiId", "Name"),
+ "AWS::AppSync::Resolver": ("ApiId", "TypeName", "FieldName"),
+ "AWS::AppSync::GraphQLSchema": ("ApiId",),
"AWS::Cognito::UserPoolGroup": ("GroupName", "UserPoolId"),
"AWS::Cognito::UserPoolResourceServer": ("Identifier", "UserPoolId"),
"AWS::Cognito::UserPoolDomain": ("Domain", "UserPoolId"),
diff --git a/tests/test_appsync.py b/tests/test_appsync.py
index 74c69c9a..b0716bd0 100644
--- a/tests/test_appsync.py
+++ b/tests/test_appsync.py
@@ -1118,6 +1118,35 @@ def test_appsync_update_data_source_and_resolver():
assert got["kind"] == "PIPELINE"
+def test_appsync_data_source_and_resolver_read_back_only_the_members_set():
+ """Unset members are absent; EventBridge config, DynamoDB defaults and maxBatchSize read back."""
+ from conftest import make_client
+ appsync = make_client("appsync")
+ api = appsync.create_graphql_api(name="members-api", authenticationType="API_KEY")["graphqlApi"]
+ api_id = api["apiId"]
+ appsync.start_schema_creation(apiId=api_id, definition=SDL.encode())
+ role = "arn:aws:iam::000000000000:role/appsync"
+ bus = {"eventBusArn": "arn:aws:events:us-east-1:000000000000:event-bus/default"}
+ appsync.create_data_source(apiId=api_id, name="none", type="NONE")
+ appsync.create_data_source(apiId=api_id, name="bus", type="AMAZON_EVENTBRIDGE",
+ serviceRoleArn=role, eventBridgeConfig=bus)
+ appsync.create_data_source(apiId=api_id, name="ddb", type="AMAZON_DYNAMODB", serviceRoleArn=role,
+ dynamodbConfig={"tableName": "items", "awsRegion": "us-east-1"})
+ sources = {d["name"]: d for d in appsync.list_data_sources(apiId=api_id)["dataSources"]}
+ assert "description" not in sources["none"] and "serviceRoleArn" not in sources["none"]
+ assert sources["bus"]["eventBridgeConfig"] == bus
+ assert sources["ddb"]["dynamodbConfig"] == {"tableName": "items", "awsRegion": "us-east-1",
+ "useCallerCredentials": False, "versioned": False}
+
+ appsync.create_resolver(apiId=api_id, typeName="Query", fieldName="hello", dataSourceName="none",
+ runtime={"name": "APPSYNC_JS", "runtimeVersion": "1.0.0"},
+ code="export function request(ctx) { return {}; }\n"
+ "export function response(ctx) { return 'hi'; }\n")
+ got = appsync.get_resolver(apiId=api_id, typeName="Query", fieldName="hello")["resolver"]
+ assert "requestMappingTemplate" not in got and "responseMappingTemplate" not in got
+ assert got["kind"] == "UNIT" and got["maxBatchSize"] == 0
+
+
def test_appsync_update_api_key():
"""UpdateApiKey changes the description without minting a new key."""
from conftest import make_client
diff --git a/tests/test_cfn.py b/tests/test_cfn.py
index f593aa14..27e64c78 100644
--- a/tests/test_cfn.py
+++ b/tests/test_cfn.py
@@ -30126,6 +30126,183 @@ def test_cfn_appsync_api_update_keeps_id_and_children(cfn, appsync):
_delete_cfn_test_stack(cfn, stack_name)
+def _cfn_appsync_query(api_id, api_key, query):
+ """The data of a query sent to the API's data plane with its API key."""
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
+ req = urllib.request.Request(
+ f"{endpoint}/v1/apis/{api_id}/graphql", method="POST",
+ data=json.dumps({"query": query}).encode(),
+ headers={"Content-Type": "application/json", "x-api-key": api_key})
+ with urllib.request.urlopen(req, timeout=10) as resp:
+ return json.loads(resp.read())["data"]
+
+
+def _cfn_appsync_resolvers_template(suffix, table, answer):
+ api_id = {"Fn::GetAtt": ["Api", "ApiId"]}
+ tables = {logical: {"Type": "AWS::DynamoDB::Table", "Properties": {
+ "TableName": f"cfn-asr-{suffix}-{logical.lower()}", "BillingMode": "PAY_PER_REQUEST",
+ "AttributeDefinitions": [{"AttributeName": "id", "AttributeType": "S"}],
+ "KeySchema": [{"AttributeName": "id", "KeyType": "HASH"}]}} for logical in ("First", "Second")}
+ return json.dumps({
+ "Resources": {
+ **tables,
+ "Api": {"Type": "AWS::AppSync::GraphQLApi",
+ "Properties": {"Name": f"asr_{suffix}", "AuthenticationType": "API_KEY"}},
+ "Key": {"Type": "AWS::AppSync::ApiKey", "Properties": {"ApiId": api_id}},
+ "Schema": {"Type": "AWS::AppSync::GraphQLSchema", "Properties": {
+ "ApiId": api_id,
+ "Definition": "type Item { id: ID! v: String }\ntype Query { item(id: ID!): Item js: String }"}},
+ "Items": {"Type": "AWS::AppSync::DataSource", "Properties": {
+ "ApiId": api_id, "Name": "items", "Type": "AMAZON_DYNAMODB",
+ "ServiceRoleArn": "arn:aws:iam::000000000000:role/appsync-items",
+ "DynamoDBConfig": {"TableName": {"Ref": table}, "AwsRegion": {"Ref": "AWS::Region"}}}},
+ "Nothing": {"Type": "AWS::AppSync::DataSource", "Properties": {
+ "ApiId": api_id, "Name": "nothing", "Type": "NONE"}},
+ "Item": {"Type": "AWS::AppSync::Resolver", "DependsOn": "Schema", "Properties": {
+ "ApiId": api_id, "TypeName": "Query", "FieldName": "item",
+ "DataSourceName": {"Fn::GetAtt": ["Items", "Name"]},
+ "RequestMappingTemplate": '{"version": "2017-02-28", "operation": "GetItem", '
+ '"key": {"id": $util.dynamodb.toDynamoDBJson($ctx.args.id)}}',
+ "ResponseMappingTemplate": "$util.toJson($ctx.result)"}},
+ "Js": {"Type": "AWS::AppSync::Resolver", "DependsOn": "Schema", "Properties": {
+ "ApiId": api_id, "TypeName": "Query", "FieldName": "js",
+ "DataSourceName": {"Fn::GetAtt": ["Nothing", "Name"]},
+ "Runtime": {"Name": "APPSYNC_JS", "RuntimeVersion": "1.0.0"},
+ "Code": f"export function request(ctx) {{ return {{ payload: '{answer}' }}; }}\n"
+ "export function response(ctx) { return ctx.result; }\n"}},
+ },
+ "Outputs": {"ApiId": {"Value": api_id}, "ApiKey": {"Value": {"Fn::GetAtt": ["Key", "ApiKey"]}}},
+ })
+
+
+def test_cfn_appsync_dynamodb_and_js_resolvers_answer_queries(cfn, ddb):
+ """A stack's DynamoDB and APPSYNC_JS resolvers answer queries, also after an update."""
+ suffix = _uuid_mod.uuid4().hex[:8]
+ stack_name = f"cfn-appsync-resolve-{suffix}"
+ query = 'query { item(id: "1") { v } js }'
+ cfn.create_stack(StackName=stack_name,
+ TemplateBody=_cfn_appsync_resolvers_template(suffix, "First", "one"))
+ try:
+ assert _wait_stack(cfn, stack_name)["StackStatus"] == "CREATE_COMPLETE"
+ for logical in ("First", "Second"):
+ ddb.put_item(TableName=f"cfn-asr-{suffix}-{logical.lower()}",
+ Item={"id": {"S": "1"}, "v": {"S": logical}})
+ api_id = _cfn_output(cfn, stack_name, "ApiId")
+ api_key = _cfn_output(cfn, stack_name, "ApiKey")
+ assert _cfn_appsync_query(api_id, api_key, query) == {"item": {"v": "First"}, "js": "one"}
+
+ cfn.update_stack(StackName=stack_name,
+ TemplateBody=_cfn_appsync_resolvers_template(suffix, "Second", "two"))
+ assert _wait_stack(cfn, stack_name)["StackStatus"] == "UPDATE_COMPLETE"
+ assert _cfn_appsync_query(api_id, api_key, query) == {"item": {"v": "Second"}, "js": "two"}
+ finally:
+ _delete_cfn_test_stack(cfn, stack_name)
+
+
+_CFN_APPSYNC_ROLE = "arn:aws:iam::000000000000:role/appsync-sources"
+_CFN_APPSYNC_FUNCTION = "arn:aws:lambda:us-east-1:000000000000:function:appsync-batch"
+_CFN_APPSYNC_BUS = "arn:aws:events:us-east-1:000000000000:event-bus/default"
+_CFN_APPSYNC_BATCH = '{"version": "2018-05-29", "operation": "BatchInvoke", "payload": $util.toJson($ctx.args)}'
+_CFN_APPSYNC_PIPE = ("export function request(ctx) { return {}; }\n"
+ "export function response(ctx) { return ctx.prev.result; }\n")
+
+
+def _cfn_appsync_members_read_back_template(suffix, updated=False, web="web"):
+ api_id = {"Fn::GetAtt": ["Api", "ApiId"]}
+ runtime = {"Name": "APPSYNC_JS", "RuntimeVersion": "1.0.0"}
+ items = {"ApiId": api_id, "Name": "items", "Type": "AMAZON_DYNAMODB", "ServiceRoleArn": _CFN_APPSYNC_ROLE,
+ "DynamoDBConfig": {"TableName": "second" if updated else "first", "AwsRegion": "us-east-1"}}
+ if not updated:
+ items["Description"] = "items"
+
+ def resolver(field, **props):
+ return {"Type": "AWS::AppSync::Resolver",
+ "Properties": {"ApiId": api_id, "TypeName": "Query", "FieldName": field, **props}}
+
+ return json.dumps({"Resources": {
+ "Api": {"Type": "AWS::AppSync::GraphQLApi",
+ "Properties": {"Name": f"asm_{suffix}", "AuthenticationType": "API_KEY"}},
+ "Items": {"Type": "AWS::AppSync::DataSource", "Properties": items},
+ "Events": {"Type": "AWS::AppSync::DataSource", "Properties": {
+ "ApiId": api_id, "Name": "events", "Type": "AMAZON_EVENTBRIDGE", "ServiceRoleArn": _CFN_APPSYNC_ROLE,
+ "EventBridgeConfig": {"EventBusArn": _CFN_APPSYNC_BUS}}},
+ "Fn": {"Type": "AWS::AppSync::DataSource", "Properties": {
+ "ApiId": api_id, "Name": "fn", "Type": "AWS_LAMBDA", "ServiceRoleArn": _CFN_APPSYNC_ROLE,
+ "LambdaConfig": {"LambdaFunctionArn": _CFN_APPSYNC_FUNCTION}}},
+ "Web": {"Type": "AWS::AppSync::DataSource", "Properties": {
+ "ApiId": api_id, "Name": web, "Type": "HTTP", "Description": "web 2" if updated else "web",
+ "HttpConfig": {"Endpoint": "https://example.org" if updated else "https://example.com"}}},
+ "Js": resolver("js", DataSourceName="events", Runtime=runtime, Code="js 2" if updated else "js"),
+ "Batch": resolver("batch", DataSourceName={"Fn::GetAtt": ["Fn", "Name"]},
+ MaxBatchSize=10 if updated else 5, RequestMappingTemplate=_CFN_APPSYNC_BATCH,
+ ResponseMappingTemplate="$util.toJson($ctx.result)"),
+ "Pipe": resolver("pipe", Kind="PIPELINE", PipelineConfig={"Functions": ["f1"]},
+ Runtime=runtime, Code=_CFN_APPSYNC_PIPE),
+ }, "Outputs": {"ApiId": {"Value": api_id}}})
+
+
+def test_cfn_appsync_data_source_and_resolver_members_read_back(cfn, appsync):
+ """Data source and resolver members read back in the API's shape after a create and an update."""
+ suffix = _uuid_mod.uuid4().hex[:8]
+ stack_name = f"cfn-appsync-members-ds-{suffix}"
+ runtime = {"name": "APPSYNC_JS", "runtimeVersion": "1.0.0"}
+
+ def sources(api_id):
+ return {d["name"]: {k: v for k, v in d.items() if k != "dataSourceArn"}
+ for d in appsync.list_data_sources(apiId=api_id)["dataSources"]}
+
+ def resolvers(api_id):
+ return {r["fieldName"]: {k: v for k, v in r.items() if k not in ("resolverArn", "typeName", "fieldName")}
+ for r in appsync.list_resolvers(apiId=api_id, typeName="Query")["resolvers"]}
+
+ def items(table):
+ return {"name": "items", "type": "AMAZON_DYNAMODB", "serviceRoleArn": _CFN_APPSYNC_ROLE,
+ "dynamodbConfig": {"tableName": table, "awsRegion": "us-east-1",
+ "useCallerCredentials": False, "versioned": False}}
+
+ cfn.create_stack(StackName=stack_name, TemplateBody=_cfn_appsync_members_read_back_template(suffix))
+ try:
+ assert _wait_stack(cfn, stack_name)["StackStatus"] == "CREATE_COMPLETE"
+ api_id = _cfn_output(cfn, stack_name, "ApiId")
+ events = {"name": "events", "type": "AMAZON_EVENTBRIDGE", "serviceRoleArn": _CFN_APPSYNC_ROLE,
+ "eventBridgeConfig": {"eventBusArn": _CFN_APPSYNC_BUS}}
+ fn = {"name": "fn", "type": "AWS_LAMBDA", "serviceRoleArn": _CFN_APPSYNC_ROLE,
+ "lambdaConfig": {"lambdaFunctionArn": _CFN_APPSYNC_FUNCTION}}
+ assert sources(api_id) == {
+ "items": {**items("first"), "description": "items"}, "events": events, "fn": fn,
+ "web": {"name": "web", "type": "HTTP", "description": "web",
+ "httpConfig": {"endpoint": "https://example.com"}}}
+ batch = {"dataSourceName": "fn", "kind": "UNIT", "requestMappingTemplate": _CFN_APPSYNC_BATCH,
+ "responseMappingTemplate": "$util.toJson($ctx.result)"}
+ pipe = {"kind": "PIPELINE", "pipelineConfig": {"functions": ["f1"]}, "maxBatchSize": 0,
+ "runtime": runtime, "code": _CFN_APPSYNC_PIPE}
+ assert resolvers(api_id) == {
+ "js": {"dataSourceName": "events", "kind": "UNIT", "maxBatchSize": 0, "runtime": runtime,
+ "code": "js"},
+ "batch": {**batch, "maxBatchSize": 5}, "pipe": pipe}
+
+ cfn.update_stack(StackName=stack_name,
+ TemplateBody=_cfn_appsync_members_read_back_template(suffix, updated=True))
+ assert _wait_stack(cfn, stack_name)["StackStatus"] == "UPDATE_COMPLETE"
+ assert sources(api_id) == {
+ "items": items("second"), "events": events, "fn": fn,
+ "web": {"name": "web", "type": "HTTP", "description": "web 2",
+ "httpConfig": {"endpoint": "https://example.org"}}}
+ assert resolvers(api_id) == {
+ "js": {"dataSourceName": "events", "kind": "UNIT", "maxBatchSize": 0, "runtime": runtime,
+ "code": "js 2"},
+ "batch": {**batch, "maxBatchSize": 10}, "pipe": pipe}
+
+ cfn.update_stack(StackName=stack_name, TemplateBody=_cfn_appsync_members_read_back_template(
+ suffix, updated=True, web="web2"))
+ assert _wait_stack(cfn, stack_name)["StackStatus"] == "UPDATE_COMPLETE"
+ assert sorted(sources(api_id)) == ["events", "fn", "items", "web2"]
+ assert "Requested update requires the creation of a new physical resource" in (
+ _stack_event_reasons(cfn, stack_name))
+ finally:
+ _delete_cfn_test_stack(cfn, stack_name)
+
+
def test_cfn_appsync_api_key_updates_in_place(cfn, appsync):
"""An API key update keeps its key id."""
suffix = _uuid_mod.uuid4().hex[:8]