From a8e18654b3b08d316976b512689a5e2e7377a368 Mon Sep 17 00:00:00 2001 From: zanhsieh Date: Mon, 16 Sep 2019 17:27:43 +0800 Subject: [PATCH 1/6] add appsync-graphql-dynamodb --- python/appsync-graphql-dynamodb/README.md | 58 ++++++ python/appsync-graphql-dynamodb/app.py | 11 ++ .../app_sync_cdk/__init__.py | 0 .../app_sync_cdk/app_sync_cdk_stack.py | 177 ++++++++++++++++++ python/appsync-graphql-dynamodb/cdk.json | 3 + .../appsync-graphql-dynamodb/requirements.txt | 4 + python/appsync-graphql-dynamodb/setup.py | 45 +++++ 7 files changed, 298 insertions(+) create mode 100644 python/appsync-graphql-dynamodb/README.md create mode 100644 python/appsync-graphql-dynamodb/app.py create mode 100644 python/appsync-graphql-dynamodb/app_sync_cdk/__init__.py create mode 100644 python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py create mode 100644 python/appsync-graphql-dynamodb/cdk.json create mode 100644 python/appsync-graphql-dynamodb/requirements.txt create mode 100644 python/appsync-graphql-dynamodb/setup.py diff --git a/python/appsync-graphql-dynamodb/README.md b/python/appsync-graphql-dynamodb/README.md new file mode 100644 index 000000000..8940aea7a --- /dev/null +++ b/python/appsync-graphql-dynamodb/README.md @@ -0,0 +1,58 @@ + +# Welcome to your CDK Python project! + +This is a blank project for Python development with CDK. + +The `cdk.json` file tells the CDK Toolkit how to execute your app. + +This project is set up like a standard Python project. The initialization +process also creates a virtualenv within this project, stored under the .env +directory. To create the virtualenv it assumes that there is a `python3` +(or `python` for Windows) executable in your path with access to the `venv` +package. If for any reason the automatic creation of the virtualenv fails, +you can create the virtualenv manually. + +To manually create a virtualenv on MacOS and Linux: + +``` +$ python3 -m venv .env +``` + +After the init process completes and the virtualenv is created, you can use the following +step to activate your virtualenv. + +``` +$ source .env/bin/activate +``` + +If you are a Windows platform, you would activate the virtualenv like this: + +``` +% .env\Scripts\activate.bat +``` + +Once the virtualenv is activated, you can install the required dependencies. + +``` +$ pip install -r requirements.txt +``` + +At this point you can now synthesize the CloudFormation template for this code. + +``` +$ cdk synth +``` + +To add additional dependencies, for example other CDK libraries, just add +them to your `setup.py` file and rerun the `pip install -r requirements.txt` +command. + +# Useful commands + + * `cdk ls` list all stacks in the app + * `cdk synth` emits the synthesized CloudFormation template + * `cdk deploy` deploy this stack to your default AWS account/region + * `cdk diff` compare deployed stack with current state + * `cdk docs` open CDK documentation + +Enjoy! diff --git a/python/appsync-graphql-dynamodb/app.py b/python/appsync-graphql-dynamodb/app.py new file mode 100644 index 000000000..6cd350643 --- /dev/null +++ b/python/appsync-graphql-dynamodb/app.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +from aws_cdk import core + +from app_sync_cdk.app_sync_cdk_stack import AppSyncCdkStack + + +app = core.App() +AppSyncCdkStack(app, "AppSyncGraphQLDynamoDBExample") + +app.synth() diff --git a/python/appsync-graphql-dynamodb/app_sync_cdk/__init__.py b/python/appsync-graphql-dynamodb/app_sync_cdk/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py b/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py new file mode 100644 index 000000000..d25c6f913 --- /dev/null +++ b/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py @@ -0,0 +1,177 @@ +from aws_cdk import core +from aws_cdk.aws_appsync import ( + CfnGraphQLSchema, + CfnGraphQLApi, + CfnApiKey, + CfnDataSource, + CfnResolver +) +from aws_cdk.aws_dynamodb import ( + Table, + Attribute, + AttributeType, + StreamViewType, + BillingMode +) +from aws_cdk.aws_iam import ( + Role, + ServicePrincipal, + ManagedPolicy +) + +class AppSyncCdkStack(core.Stack): + + def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: + super().__init__(scope, id, **kwargs) + + table_name = 'items' + + items_graphql_api = CfnGraphQLApi( + self, 'ItemsApi', + name='items-api', + authentication_type='API_KEY' + ) + + CfnApiKey( + self, 'ItemsApiKey', + api_id=items_graphql_api.attr_api_id + ) + + api_schema = CfnGraphQLSchema( + self, 'ItemsSchema', + api_id=items_graphql_api.attr_api_id, + definition=f"""\ + type {table_name} {{ + {table_name}Id: ID! + name: String + }} + type Paginated{table_name} {{ + items: [{table_name}!]! + nextToken: String + }} + type Query {{ + all(limit: Int, nextToken: String): Paginated{table_name}! + getOne({table_name}Id: ID!): {table_name} + }} + type Mutation {{ + save(name: String!): {table_name} + delete({table_name}Id: ID!): {table_name} + }} + type Schema {{ + query: Query + mutation: Mutation + }}""" + ) + + items_table = Table( + self, 'ItemsTable', + table_name=table_name, + partition_key=Attribute( + name=f'{table_name}Id', + type=AttributeType.STRING + ), + billing_mode=BillingMode.PAY_PER_REQUEST, + stream=StreamViewType.NEW_IMAGE, + + ## The default removal policy is RETAIN, which means that cdk destroy will not attempt to delete + ## the new table, and it will remain in your account until manually deleted. By setting the policy to + ## DESTROY, cdk destroy will delete the table (even if it has data in it) + removal_policy=core.RemovalPolicy.DESTROY ## NOT recommended for production code + ) + + items_table_role = Role( + self, 'ItemsDynamoDBRole', + assumed_by=ServicePrincipal('appsync.amazonaws.com') + ) + + items_table_role.add_managed_policy(ManagedPolicy.from_aws_managed_policy_name('arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess')) + + data_source = CfnDataSource( + self, 'ItemsDataSource', + api_id=items_graphql_api.attr_api_id, + name='ItemsDynamoDataSource', + type='AMAZON_DYNAMODB', + dynamo_db_config=CfnDataSource.DynamoDBConfigProperty( + table_name=items_table.table_name, + aws_region=self.region + ), + service_role_arn=items_table_role.role_arn + ) + + get_one_resolver = CfnResolver( + self, 'GetOneQueryResolver', + api_id=items_graphql_api.attr_api_id, + type_name='Query', + field_name='getOne', + data_source_name=data_source.name, + request_mapping_template=f"""\ + {{ + "version": "2017-02-28", + "operation": "GetItem", + "key": {{ + "{table_name}Id": $util.dynamodb.toDynamoDBJson($ctx.args.{table_name}Id) + }} + }}""", + response_mapping_template="$util.toJson($ctx.result)" + ) + + get_one_resolver.add_depends_on(api_schema) + + get_all_resolver = CfnResolver( + self, 'GetAllQueryResolver', + api_id=items_graphql_api.attr_api_id, + type_name='Query', + field_name='all', + data_source_name=data_source.name, + request_mapping_template=f"""\ + {{ + "version": "2017-02-28", + "operation": "Scan", + "limit": $util.defaultIfNull($ctx.args.limit, 20), + "nextToken": $util.toJson($util.defaultIfNullOrEmpty($ctx.args.nextToken, null)) + }}""", + response_mapping_template="$util.toJson($ctx.result)" + ) + + get_all_resolver.add_depends_on(api_schema) + + save_resolver = CfnResolver( + self, 'SaveMutationResolver', + api_id=items_graphql_api.attr_api_id, + type_name='Mutation', + field_name='save', + data_source_name=data_source.name, + request_mapping_template=f"""\ + {{ + "version": "2017-02-28", + "operation": "PutItem", + "key": {{ + "{table_name}Id": {{ "S": "$util.autoId()" }} + }}, + "attributeValues": {{ + "name": $util.dynamodb.toDynamoDBJson($ctx.args.name) + }} + }}""", + response_mapping_template="$util.toJson($ctx.result)" + ) + + save_resolver.add_depends_on(api_schema) + + delete_resolver = CfnResolver( + self, 'DeleteMutationResolver', + api_id=items_graphql_api.attr_api_id, + type_name='Mutation', + field_name='delete', + data_source_name=data_source.name, + request_mapping_template=f"""\ + {{ + "version": "2017-02-28", + "operation": "DeleteItem", + "key": {{ + "{table_name}Id": $util.dynamodb.toDynamoDBJson($ctx.args.{table_name}Id) + }} + }}""", + response_mapping_template="$util.toJson($ctx.result)" + ) + + delete_resolver.add_depends_on(api_schema) \ No newline at end of file diff --git a/python/appsync-graphql-dynamodb/cdk.json b/python/appsync-graphql-dynamodb/cdk.json new file mode 100644 index 000000000..787a71dd6 --- /dev/null +++ b/python/appsync-graphql-dynamodb/cdk.json @@ -0,0 +1,3 @@ +{ + "app": "python3 app.py" +} diff --git a/python/appsync-graphql-dynamodb/requirements.txt b/python/appsync-graphql-dynamodb/requirements.txt new file mode 100644 index 000000000..8af60b896 --- /dev/null +++ b/python/appsync-graphql-dynamodb/requirements.txt @@ -0,0 +1,4 @@ +aws_cdk.core +aws_cdk.aws_appsync +aws_cdk.aws_dynamodb +aws_cdk.aws_iam \ No newline at end of file diff --git a/python/appsync-graphql-dynamodb/setup.py b/python/appsync-graphql-dynamodb/setup.py new file mode 100644 index 000000000..d695b4aa6 --- /dev/null +++ b/python/appsync-graphql-dynamodb/setup.py @@ -0,0 +1,45 @@ +import setuptools + + +with open("README.md") as fp: + long_description = fp.read() + + +setuptools.setup( + name="app_sync_cdk", + version="0.0.1", + + description="An empty CDK Python app", + long_description=long_description, + long_description_content_type="text/markdown", + + author="author", + + package_dir={"": "app_sync_cdk"}, + packages=setuptools.find_packages(where="app_sync_cdk"), + + install_requires=[ + "aws-cdk.core", + ], + + python_requires=">=3.6", + + classifiers=[ + "Development Status :: 4 - Beta", + + "Intended Audience :: Developers", + + "License :: OSI Approved :: Apache Software License", + + "Programming Language :: JavaScript", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + + "Topic :: Software Development :: Code Generators", + "Topic :: Utilities", + + "Typing :: Typed", + ], +) From b2b577be01c482a20b224a61e0ee7777353df932 Mon Sep 17 00:00:00 2001 From: zanhsieh Date: Mon, 16 Sep 2019 17:27:43 +0800 Subject: [PATCH 2/6] add appsync-graphql-dynamodb --- python/appsync-graphql-dynamodb/app.py | 11 ++ .../app_sync_cdk/__init__.py | 0 .../app_sync_cdk/app_sync_cdk_stack.py | 177 ++++++++++++++++++ python/appsync-graphql-dynamodb/cdk.json | 3 + .../appsync-graphql-dynamodb/requirements.txt | 4 + python/appsync-graphql-dynamodb/setup.py | 45 +++++ 6 files changed, 240 insertions(+) create mode 100644 python/appsync-graphql-dynamodb/app.py create mode 100644 python/appsync-graphql-dynamodb/app_sync_cdk/__init__.py create mode 100644 python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py create mode 100644 python/appsync-graphql-dynamodb/cdk.json create mode 100644 python/appsync-graphql-dynamodb/requirements.txt create mode 100644 python/appsync-graphql-dynamodb/setup.py diff --git a/python/appsync-graphql-dynamodb/app.py b/python/appsync-graphql-dynamodb/app.py new file mode 100644 index 000000000..6cd350643 --- /dev/null +++ b/python/appsync-graphql-dynamodb/app.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +from aws_cdk import core + +from app_sync_cdk.app_sync_cdk_stack import AppSyncCdkStack + + +app = core.App() +AppSyncCdkStack(app, "AppSyncGraphQLDynamoDBExample") + +app.synth() diff --git a/python/appsync-graphql-dynamodb/app_sync_cdk/__init__.py b/python/appsync-graphql-dynamodb/app_sync_cdk/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py b/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py new file mode 100644 index 000000000..d25c6f913 --- /dev/null +++ b/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py @@ -0,0 +1,177 @@ +from aws_cdk import core +from aws_cdk.aws_appsync import ( + CfnGraphQLSchema, + CfnGraphQLApi, + CfnApiKey, + CfnDataSource, + CfnResolver +) +from aws_cdk.aws_dynamodb import ( + Table, + Attribute, + AttributeType, + StreamViewType, + BillingMode +) +from aws_cdk.aws_iam import ( + Role, + ServicePrincipal, + ManagedPolicy +) + +class AppSyncCdkStack(core.Stack): + + def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: + super().__init__(scope, id, **kwargs) + + table_name = 'items' + + items_graphql_api = CfnGraphQLApi( + self, 'ItemsApi', + name='items-api', + authentication_type='API_KEY' + ) + + CfnApiKey( + self, 'ItemsApiKey', + api_id=items_graphql_api.attr_api_id + ) + + api_schema = CfnGraphQLSchema( + self, 'ItemsSchema', + api_id=items_graphql_api.attr_api_id, + definition=f"""\ + type {table_name} {{ + {table_name}Id: ID! + name: String + }} + type Paginated{table_name} {{ + items: [{table_name}!]! + nextToken: String + }} + type Query {{ + all(limit: Int, nextToken: String): Paginated{table_name}! + getOne({table_name}Id: ID!): {table_name} + }} + type Mutation {{ + save(name: String!): {table_name} + delete({table_name}Id: ID!): {table_name} + }} + type Schema {{ + query: Query + mutation: Mutation + }}""" + ) + + items_table = Table( + self, 'ItemsTable', + table_name=table_name, + partition_key=Attribute( + name=f'{table_name}Id', + type=AttributeType.STRING + ), + billing_mode=BillingMode.PAY_PER_REQUEST, + stream=StreamViewType.NEW_IMAGE, + + ## The default removal policy is RETAIN, which means that cdk destroy will not attempt to delete + ## the new table, and it will remain in your account until manually deleted. By setting the policy to + ## DESTROY, cdk destroy will delete the table (even if it has data in it) + removal_policy=core.RemovalPolicy.DESTROY ## NOT recommended for production code + ) + + items_table_role = Role( + self, 'ItemsDynamoDBRole', + assumed_by=ServicePrincipal('appsync.amazonaws.com') + ) + + items_table_role.add_managed_policy(ManagedPolicy.from_aws_managed_policy_name('arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess')) + + data_source = CfnDataSource( + self, 'ItemsDataSource', + api_id=items_graphql_api.attr_api_id, + name='ItemsDynamoDataSource', + type='AMAZON_DYNAMODB', + dynamo_db_config=CfnDataSource.DynamoDBConfigProperty( + table_name=items_table.table_name, + aws_region=self.region + ), + service_role_arn=items_table_role.role_arn + ) + + get_one_resolver = CfnResolver( + self, 'GetOneQueryResolver', + api_id=items_graphql_api.attr_api_id, + type_name='Query', + field_name='getOne', + data_source_name=data_source.name, + request_mapping_template=f"""\ + {{ + "version": "2017-02-28", + "operation": "GetItem", + "key": {{ + "{table_name}Id": $util.dynamodb.toDynamoDBJson($ctx.args.{table_name}Id) + }} + }}""", + response_mapping_template="$util.toJson($ctx.result)" + ) + + get_one_resolver.add_depends_on(api_schema) + + get_all_resolver = CfnResolver( + self, 'GetAllQueryResolver', + api_id=items_graphql_api.attr_api_id, + type_name='Query', + field_name='all', + data_source_name=data_source.name, + request_mapping_template=f"""\ + {{ + "version": "2017-02-28", + "operation": "Scan", + "limit": $util.defaultIfNull($ctx.args.limit, 20), + "nextToken": $util.toJson($util.defaultIfNullOrEmpty($ctx.args.nextToken, null)) + }}""", + response_mapping_template="$util.toJson($ctx.result)" + ) + + get_all_resolver.add_depends_on(api_schema) + + save_resolver = CfnResolver( + self, 'SaveMutationResolver', + api_id=items_graphql_api.attr_api_id, + type_name='Mutation', + field_name='save', + data_source_name=data_source.name, + request_mapping_template=f"""\ + {{ + "version": "2017-02-28", + "operation": "PutItem", + "key": {{ + "{table_name}Id": {{ "S": "$util.autoId()" }} + }}, + "attributeValues": {{ + "name": $util.dynamodb.toDynamoDBJson($ctx.args.name) + }} + }}""", + response_mapping_template="$util.toJson($ctx.result)" + ) + + save_resolver.add_depends_on(api_schema) + + delete_resolver = CfnResolver( + self, 'DeleteMutationResolver', + api_id=items_graphql_api.attr_api_id, + type_name='Mutation', + field_name='delete', + data_source_name=data_source.name, + request_mapping_template=f"""\ + {{ + "version": "2017-02-28", + "operation": "DeleteItem", + "key": {{ + "{table_name}Id": $util.dynamodb.toDynamoDBJson($ctx.args.{table_name}Id) + }} + }}""", + response_mapping_template="$util.toJson($ctx.result)" + ) + + delete_resolver.add_depends_on(api_schema) \ No newline at end of file diff --git a/python/appsync-graphql-dynamodb/cdk.json b/python/appsync-graphql-dynamodb/cdk.json new file mode 100644 index 000000000..787a71dd6 --- /dev/null +++ b/python/appsync-graphql-dynamodb/cdk.json @@ -0,0 +1,3 @@ +{ + "app": "python3 app.py" +} diff --git a/python/appsync-graphql-dynamodb/requirements.txt b/python/appsync-graphql-dynamodb/requirements.txt new file mode 100644 index 000000000..8af60b896 --- /dev/null +++ b/python/appsync-graphql-dynamodb/requirements.txt @@ -0,0 +1,4 @@ +aws_cdk.core +aws_cdk.aws_appsync +aws_cdk.aws_dynamodb +aws_cdk.aws_iam \ No newline at end of file diff --git a/python/appsync-graphql-dynamodb/setup.py b/python/appsync-graphql-dynamodb/setup.py new file mode 100644 index 000000000..d695b4aa6 --- /dev/null +++ b/python/appsync-graphql-dynamodb/setup.py @@ -0,0 +1,45 @@ +import setuptools + + +with open("README.md") as fp: + long_description = fp.read() + + +setuptools.setup( + name="app_sync_cdk", + version="0.0.1", + + description="An empty CDK Python app", + long_description=long_description, + long_description_content_type="text/markdown", + + author="author", + + package_dir={"": "app_sync_cdk"}, + packages=setuptools.find_packages(where="app_sync_cdk"), + + install_requires=[ + "aws-cdk.core", + ], + + python_requires=">=3.6", + + classifiers=[ + "Development Status :: 4 - Beta", + + "Intended Audience :: Developers", + + "License :: OSI Approved :: Apache Software License", + + "Programming Language :: JavaScript", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + + "Topic :: Software Development :: Code Generators", + "Topic :: Utilities", + + "Typing :: Typed", + ], +) From 1d3387905da77e939dc7a28e08d8e5c65f223fa0 Mon Sep 17 00:00:00 2001 From: zanhsieh Date: Mon, 16 Sep 2019 17:29:59 +0800 Subject: [PATCH 3/6] Delete README.md --- python/appsync-graphql-dynamodb/README.md | 58 ----------------------- 1 file changed, 58 deletions(-) delete mode 100644 python/appsync-graphql-dynamodb/README.md diff --git a/python/appsync-graphql-dynamodb/README.md b/python/appsync-graphql-dynamodb/README.md deleted file mode 100644 index 8940aea7a..000000000 --- a/python/appsync-graphql-dynamodb/README.md +++ /dev/null @@ -1,58 +0,0 @@ - -# Welcome to your CDK Python project! - -This is a blank project for Python development with CDK. - -The `cdk.json` file tells the CDK Toolkit how to execute your app. - -This project is set up like a standard Python project. The initialization -process also creates a virtualenv within this project, stored under the .env -directory. To create the virtualenv it assumes that there is a `python3` -(or `python` for Windows) executable in your path with access to the `venv` -package. If for any reason the automatic creation of the virtualenv fails, -you can create the virtualenv manually. - -To manually create a virtualenv on MacOS and Linux: - -``` -$ python3 -m venv .env -``` - -After the init process completes and the virtualenv is created, you can use the following -step to activate your virtualenv. - -``` -$ source .env/bin/activate -``` - -If you are a Windows platform, you would activate the virtualenv like this: - -``` -% .env\Scripts\activate.bat -``` - -Once the virtualenv is activated, you can install the required dependencies. - -``` -$ pip install -r requirements.txt -``` - -At this point you can now synthesize the CloudFormation template for this code. - -``` -$ cdk synth -``` - -To add additional dependencies, for example other CDK libraries, just add -them to your `setup.py` file and rerun the `pip install -r requirements.txt` -command. - -# Useful commands - - * `cdk ls` list all stacks in the app - * `cdk synth` emits the synthesized CloudFormation template - * `cdk deploy` deploy this stack to your default AWS account/region - * `cdk diff` compare deployed stack with current state - * `cdk docs` open CDK documentation - -Enjoy! From 220a104ba71247480a71a4587dd4ea631d7dedd9 Mon Sep 17 00:00:00 2001 From: zanhsieh Date: Mon, 16 Sep 2019 17:38:48 +0800 Subject: [PATCH 4/6] feat: add appsync-graphql-dynamodb python example --- .../app_sync_cdk/app_sync_cdk_stack.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py b/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py index d25c6f913..307387a42 100644 --- a/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py +++ b/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py @@ -174,4 +174,6 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: response_mapping_template="$util.toJson($ctx.result)" ) - delete_resolver.add_depends_on(api_schema) \ No newline at end of file + delete_resolver.add_depends_on(api_schema) + + From 3ddfa03468a578a2b21887d41753d4941d159545 Mon Sep 17 00:00:00 2001 From: zanhsieh Date: Wed, 18 Sep 2019 04:50:26 +0800 Subject: [PATCH 5/6] pep8 lint --- .../app_sync_cdk/app_sync_cdk_stack.py | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py b/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py index 307387a42..6fb3d1360 100644 --- a/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py +++ b/python/appsync-graphql-dynamodb/app_sync_cdk/app_sync_cdk_stack.py @@ -19,6 +19,7 @@ ManagedPolicy ) + class AppSyncCdkStack(core.Stack): def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: @@ -33,7 +34,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: ) CfnApiKey( - self, 'ItemsApiKey', + self, 'ItemsApiKey', api_id=items_graphql_api.attr_api_id ) @@ -73,10 +74,12 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: billing_mode=BillingMode.PAY_PER_REQUEST, stream=StreamViewType.NEW_IMAGE, - ## The default removal policy is RETAIN, which means that cdk destroy will not attempt to delete - ## the new table, and it will remain in your account until manually deleted. By setting the policy to - ## DESTROY, cdk destroy will delete the table (even if it has data in it) - removal_policy=core.RemovalPolicy.DESTROY ## NOT recommended for production code + # The default removal policy is RETAIN, which means that cdk + # destroy will not attempt to delete the new table, and it will + # remain in your account until manually deleted. By setting the + # policy to DESTROY, cdk destroy will delete the table (even if it + # has data in it) + removal_policy=core.RemovalPolicy.DESTROY # NOT recommended for production code ) items_table_role = Role( @@ -84,10 +87,14 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: assumed_by=ServicePrincipal('appsync.amazonaws.com') ) - items_table_role.add_managed_policy(ManagedPolicy.from_aws_managed_policy_name('arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess')) + items_table_role.add_managed_policy( + ManagedPolicy.from_aws_managed_policy_name( + 'arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess' + ) + ) data_source = CfnDataSource( - self, 'ItemsDataSource', + self, 'ItemsDataSource', api_id=items_graphql_api.attr_api_id, name='ItemsDynamoDataSource', type='AMAZON_DYNAMODB', @@ -99,7 +106,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: ) get_one_resolver = CfnResolver( - self, 'GetOneQueryResolver', + self, 'GetOneQueryResolver', api_id=items_graphql_api.attr_api_id, type_name='Query', field_name='getOne', @@ -118,7 +125,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: get_one_resolver.add_depends_on(api_schema) get_all_resolver = CfnResolver( - self, 'GetAllQueryResolver', + self, 'GetAllQueryResolver', api_id=items_graphql_api.attr_api_id, type_name='Query', field_name='all', @@ -136,7 +143,7 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: get_all_resolver.add_depends_on(api_schema) save_resolver = CfnResolver( - self, 'SaveMutationResolver', + self, 'SaveMutationResolver', api_id=items_graphql_api.attr_api_id, type_name='Mutation', field_name='save', @@ -174,6 +181,4 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: response_mapping_template="$util.toJson($ctx.result)" ) - delete_resolver.add_depends_on(api_schema) - - + delete_resolver.add_depends_on(api_schema) \ No newline at end of file From d87a2d697f69e60e5c0b0a5a6ebc744b197288ef Mon Sep 17 00:00:00 2001 From: zanhsieh Date: Wed, 18 Sep 2019 04:53:46 +0800 Subject: [PATCH 6/6] rm setup.py --- python/appsync-graphql-dynamodb/setup.py | 45 ------------------------ 1 file changed, 45 deletions(-) delete mode 100644 python/appsync-graphql-dynamodb/setup.py diff --git a/python/appsync-graphql-dynamodb/setup.py b/python/appsync-graphql-dynamodb/setup.py deleted file mode 100644 index d695b4aa6..000000000 --- a/python/appsync-graphql-dynamodb/setup.py +++ /dev/null @@ -1,45 +0,0 @@ -import setuptools - - -with open("README.md") as fp: - long_description = fp.read() - - -setuptools.setup( - name="app_sync_cdk", - version="0.0.1", - - description="An empty CDK Python app", - long_description=long_description, - long_description_content_type="text/markdown", - - author="author", - - package_dir={"": "app_sync_cdk"}, - packages=setuptools.find_packages(where="app_sync_cdk"), - - install_requires=[ - "aws-cdk.core", - ], - - python_requires=">=3.6", - - classifiers=[ - "Development Status :: 4 - Beta", - - "Intended Audience :: Developers", - - "License :: OSI Approved :: Apache Software License", - - "Programming Language :: JavaScript", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - - "Topic :: Software Development :: Code Generators", - "Topic :: Utilities", - - "Typing :: Typed", - ], -)