From e236978fadc01ca6abdc9bc86292ec6298b0cbe9 Mon Sep 17 00:00:00 2001 From: Aleksandar Simovic Date: Mon, 27 May 2019 00:42:04 +0200 Subject: [PATCH 01/11] adding the AppSync GraphQL DynamoDB example --- README.md | 1 + typescript/appsync-graphql-dynamodb/README.md | 17 ++ typescript/appsync-graphql-dynamodb/cdk.json | 3 + typescript/appsync-graphql-dynamodb/index.ts | 145 ++++++++++++++++++ .../appsync-graphql-dynamodb/package.json | 26 ++++ .../appsync-graphql-dynamodb/tsconfig.json | 21 +++ 6 files changed, 213 insertions(+) create mode 100644 typescript/appsync-graphql-dynamodb/README.md create mode 100644 typescript/appsync-graphql-dynamodb/cdk.json create mode 100644 typescript/appsync-graphql-dynamodb/index.ts create mode 100644 typescript/appsync-graphql-dynamodb/package.json create mode 100644 typescript/appsync-graphql-dynamodb/tsconfig.json diff --git a/README.md b/README.md index f2140ab2e3..1ec75c59fb 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ $ cdk destroy |---------|-------------| | [api-cors-lambda-crud-dynamodb](https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/api-cors-lambda-crud-dynamodb/) | Creating a single API with CORS, and five Lambdas doing CRUD operations over a single DynamoDB | | [application-load-balancer](https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/application-load-balancer/) | Using an AutoScalingGroup with an Application Load Balancer | +| [appsync-graphql-dynamodb](https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/appsync-graphql-dynamodb/) | Creating a single GraphQL API with an API Key, and four Resolvers doing CRUD operations over a single DynamoDB | | [classic-load-balancer](https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/classic-load-balancer/) | Using an AutoScalingGroup with a Classic Load Balancer | | [custom-resource](https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/custom-resource/) | Shows adding a Custom Resource to your CDK app | | [elasticbeanstalk](https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/elasticbeanstalk/) | Elastic Beanstalk example using L1 with a Blue/Green pipeline (community contributed) | diff --git a/typescript/appsync-graphql-dynamodb/README.md b/typescript/appsync-graphql-dynamodb/README.md new file mode 100644 index 0000000000..26db04d862 --- /dev/null +++ b/typescript/appsync-graphql-dynamodb/README.md @@ -0,0 +1,17 @@ +# AppSync GraphQL API with four resolvers CRUD with DynamoDB + +This an example of an AppSync GraphQL API, pointing to four resolvers doing CRUD operations with a single DynamoDB table. + +## The Component Structure + +This Stack contains: + +- a GraphQL API with an API Key (Use with caution, each key is only valid for 7 days.) +- a GraphQL Schema with Queries to get one and all items and two mutations to save and delete an item +- a DynamoDB table `items` that stores the data with a Pay Per Request Billing Mode +- an IAM Role that allows AppSync to invoke your DynamoDB table. +- a DataSource, connecting your API to the DynamoDB table with the previously specified role. +- a Resolver for a Query `getOne` to get one item from the DynamoDB table. +- a Resolver for a Query `all` to get all items from the DynamoDB table. +- a Resolver for a Mutation `save` to put an item into the DynamoDB table (the id is autogenerated, you need only name). +- a Resolver for a Mutation `delete` to delete one item from the DynamoDB table. diff --git a/typescript/appsync-graphql-dynamodb/cdk.json b/typescript/appsync-graphql-dynamodb/cdk.json new file mode 100644 index 0000000000..cc2ccbdf87 --- /dev/null +++ b/typescript/appsync-graphql-dynamodb/cdk.json @@ -0,0 +1,3 @@ +{ + "app": "node index" +} diff --git a/typescript/appsync-graphql-dynamodb/index.ts b/typescript/appsync-graphql-dynamodb/index.ts new file mode 100644 index 0000000000..42586f179d --- /dev/null +++ b/typescript/appsync-graphql-dynamodb/index.ts @@ -0,0 +1,145 @@ +import cdk = require('@aws-cdk/cdk'); +import { CfnGraphQLApi, CfnApiKey, CfnGraphQLSchema, CfnDataSource, CfnResolver } from '@aws-cdk/aws-appsync'; +import { Table, AttributeType, StreamViewType, BillingMode } from '@aws-cdk/aws-dynamodb'; +import { Role, ServicePrincipal } from '@aws-cdk/aws-iam'; + + +export class AppSyncCdkStack extends cdk.Stack { + + constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { + super(scope, id, props); + + const tableName = 'items' + + const itemsGraphQLApi = new CfnGraphQLApi(this, 'ItemsApi', { + name: 'items-api', + authenticationType: 'API_KEY' + }); + + new CfnApiKey(this, 'ItemsApiKey', { + apiId: itemsGraphQLApi.graphQlApiApiId + }); + + const apiSchema = new CfnGraphQLSchema(this, 'ItemsSchema', { + apiId: itemsGraphQLApi.graphQlApiApiId, + definition: `type ${tableName} { + ${tableName}Id: ID! + name: String + } + type Paginated${tableName} { + items: [${tableName}!]! + nextToken: String + } + type Query { + all(limit: Int, nextToken: String): Paginated${tableName}! + getOne(${tableName}Id: ID!): ${tableName} + } + type Mutation { + save(name: String!): ${tableName} + delete(${tableName}Id: ID!): ${tableName} + } + type Schema { + query: Query + mutation: Mutation + }` + }); + + const itemsTable = new Table(this, 'ItemsTable', { + tableName: tableName, + partitionKey: { + name: `${tableName}Id`, + type: AttributeType.String + }, + billingMode: BillingMode.PayPerRequest, + streamSpecification: StreamViewType.NewImage + }); + + const itemsTableRole = new Role(this, 'ItemsDynamoDBRole', { + assumedBy: new ServicePrincipal('appsync.amazonaws.com') + }); + + itemsTableRole.attachManagedPolicy('arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess'); + + const dataSource = new CfnDataSource(this, 'ItemsDataSource', { + apiId: itemsGraphQLApi.graphQlApiApiId, + name: 'ItemsDynamoDataSource', + type: 'AMAZON_DYNAMODB', + dynamoDbConfig: { + tableName: itemsTable.tableName, + awsRegion: this.region + }, + serviceRoleArn: itemsTableRole.roleArn + }); + + const getOneResolver = new CfnResolver(this, 'GetOneQueryResolver', { + apiId: itemsGraphQLApi.graphQlApiApiId, + typeName: 'Query', + fieldName: 'getOne', + dataSourceName: dataSource.dataSourceName, + requestMappingTemplate: `{ + "version": "2017-02-28", + "operation": "GetItem", + "key": { + "${tableName}Id": $util.dynamodb.toDynamoDBJson($ctx.args.${tableName}Id) + } + }`, + responseMappingTemplate: `$util.toJson($ctx.result)` + }); + getOneResolver.addDependsOn(apiSchema); + + const getAllResolver = new CfnResolver(this, 'GetAllQueryResolver', { + apiId: itemsGraphQLApi.graphQlApiApiId, + typeName: 'Query', + fieldName: 'all', + dataSourceName: dataSource.dataSourceName, + requestMappingTemplate: `{ + "version": "2017-02-28", + "operation": "Scan", + "limit": $util.defaultIfNull($ctx.args.limit, 20), + "nextToken": $util.toJson($util.defaultIfNullOrEmpty($ctx.args.nextToken, null)) + }`, + responseMappingTemplate: `$util.toJson($ctx.result)` + }); + getAllResolver.addDependsOn(apiSchema); + + const saveResolver = new CfnResolver(this, 'SaveMutationResolver', { + apiId: itemsGraphQLApi.graphQlApiApiId, + typeName: 'Mutation', + fieldName: 'save', + dataSourceName: dataSource.dataSourceName, + requestMappingTemplate: `{ + "version": "2017-02-28", + "operation": "PutItem", + "key": { + "${tableName}Id": { "S": "$util.autoId()" } + }, + "attributeValues": { + "name": $util.dynamodb.toDynamoDBJson($ctx.args.name) + } + }`, + responseMappingTemplate: `$util.toJson($ctx.result)` + }); + saveResolver.addDependsOn(apiSchema); + + const deleteResolver = new CfnResolver(this, 'DeleteMutationResolver', { + apiId: itemsGraphQLApi.graphQlApiApiId, + typeName: 'Mutation', + fieldName: 'delete', + dataSourceName: dataSource.dataSourceName, + requestMappingTemplate: `{ + "version": "2017-02-28", + "operation": "DeleteItem", + "key": { + "${tableName}Id": $util.dynamodb.toDynamoDBJson($ctx.args.${tableName}Id) + } + }`, + responseMappingTemplate: `$util.toJson($ctx.result)` + }); + deleteResolver.addDependsOn(apiSchema); + + } +} + +const app = new cdk.App(); +new AppSyncCdkStack(app, 'AppSyncGraphQLDynamoDBExample'); +app.run(); diff --git a/typescript/appsync-graphql-dynamodb/package.json b/typescript/appsync-graphql-dynamodb/package.json new file mode 100644 index 0000000000..acc53eb4ed --- /dev/null +++ b/typescript/appsync-graphql-dynamodb/package.json @@ -0,0 +1,26 @@ +{ + "name": "appsync-graphql-dynamodb", + "version": "0.23.0", + "description": "Running a GraphQL API with four resolvers to do CRUD operations on DynamoDB", + "private": true, + "scripts": { + "build": "tsc", + "watch": "tsc -w", + "cdk": "cdk" + }, + "author": { + "name": "Aleksandar Simovic ", + "url": "https://serverless.pub" + }, + "license": "MIT", + "devDependencies": { + "@types/node": "^8.10.38", + "typescript": "^3.2.4" + }, + "dependencies": { + "@aws-cdk/aws-appsync": "*", + "@aws-cdk/aws-dynamodb": "*", + "@aws-cdk/aws-iam": "*", + "@aws-cdk/cdk": "*" + } +} diff --git a/typescript/appsync-graphql-dynamodb/tsconfig.json b/typescript/appsync-graphql-dynamodb/tsconfig.json new file mode 100644 index 0000000000..f2e82ef876 --- /dev/null +++ b/typescript/appsync-graphql-dynamodb/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "target":"ES2018", + "module": "commonjs", + "lib": ["es2016", "es2017.object", "es2017.string"], + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "noImplicitThis": true, + "alwaysStrict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": false, + "inlineSourceMap": true, + "inlineSources": true, + "experimentalDecorators": true, + "strictPropertyInitialization":false + } +} + From 1db2e686196bb0034bf8a51c1428af71f60e1e4a Mon Sep 17 00:00:00 2001 From: Aleksandar Simovic Date: Mon, 27 May 2019 01:00:11 +0200 Subject: [PATCH 02/11] adding a fix for the changed ec2.VpcNetwork to ec2.Vpc --- typescript/classic-load-balancer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/classic-load-balancer/index.ts b/typescript/classic-load-balancer/index.ts index 62aa1f49ef..ea6a90eca2 100644 --- a/typescript/classic-load-balancer/index.ts +++ b/typescript/classic-load-balancer/index.ts @@ -8,7 +8,7 @@ class LoadBalancerStack extends cdk.Stack { constructor(app: cdk.App, id: string) { super(app, id); - const vpc = new ec2.VpcNetwork(this, 'VPC'); + const vpc = new ec2.Vpc(this, 'VPC'); const asg = new autoscaling.AutoScalingGroup(this, 'ASG', { vpc, From d84f26f70856ac8ce5db7b58cd58ffc7e2c0b752 Mon Sep 17 00:00:00 2001 From: Aleksandar Simovic Date: Mon, 27 May 2019 01:07:44 +0200 Subject: [PATCH 03/11] adding a fix for the changed events.EventRule to events.Rule --- typescript/lambda-cron/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/lambda-cron/index.ts b/typescript/lambda-cron/index.ts index 11fcf04d2f..62339e5f84 100644 --- a/typescript/lambda-cron/index.ts +++ b/typescript/lambda-cron/index.ts @@ -18,7 +18,7 @@ export class LambdaCronStack extends cdk.Stack { // Run every day at 6PM UTC // See https://docs.aws.amazon.com/lambda/latest/dg/tutorial-scheduled-events-schedule-expressions.html - const rule = new events.EventRule(this, 'Rule', { + const rule = new events.Rule(this, 'Rule', { scheduleExpression: 'cron(0 18 ? * MON-FRI *)', }); From 71352855cdb78b41ffc2918f107076987324d1fb Mon Sep 17 00:00:00 2001 From: Aleksandar Simovic Date: Mon, 27 May 2019 13:49:31 +0200 Subject: [PATCH 04/11] fixing the switch from ec2.VpcNetwork to ec2.Vpc --- typescript/application-load-balancer/index.ts | 2 +- typescript/ecs/cluster/index.ts | 3 +-- typescript/ecs/ecs-load-balanced-service/index.ts | 2 +- typescript/ecs/ecs-service-with-advanced-alb-config/index.ts | 2 +- typescript/ecs/ecs-service-with-logging/index.ts | 2 +- typescript/ecs/ecs-service-with-task-networking/index.ts | 4 ++-- typescript/ecs/ecs-service-with-task-placement/index.ts | 2 +- typescript/ecs/fargate-load-balanced-service/index.ts | 2 +- typescript/ecs/fargate-service-with-auto-scaling/index.ts | 2 +- typescript/ecs/fargate-service-with-local-image/index.ts | 2 +- typescript/ecs/fargate-service-with-logging/index.ts | 2 +- typescript/resource-overrides/index.ts | 2 +- 12 files changed, 13 insertions(+), 14 deletions(-) diff --git a/typescript/application-load-balancer/index.ts b/typescript/application-load-balancer/index.ts index 9224ffffb3..2f2910bf48 100644 --- a/typescript/application-load-balancer/index.ts +++ b/typescript/application-load-balancer/index.ts @@ -8,7 +8,7 @@ class LoadBalancerStack extends cdk.Stack { constructor(app: cdk.App, id: string) { super(app, id); - const vpc = new ec2.VpcNetwork(this, 'VPC'); + const vpc = new ec2.Vpc(this, 'VPC'); const asg = new autoscaling.AutoScalingGroup(this, 'ASG', { vpc, diff --git a/typescript/ecs/cluster/index.ts b/typescript/ecs/cluster/index.ts index 5f8f62f847..425e8651fa 100644 --- a/typescript/ecs/cluster/index.ts +++ b/typescript/ecs/cluster/index.ts @@ -8,7 +8,7 @@ class ECSCluster extends cdk.Stack { constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { super(scope, id, props); - const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 2 }); + const vpc = new ec2.VPC(this, 'MyVpc', { maxAZs: 2 }); const asg = new autoscaling.AutoScalingGroup(this, 'MyFleet', { instanceType: new InstanceType("t2.xlarge"), @@ -33,4 +33,3 @@ const app = new cdk.App(); new ECSCluster(app, 'MyFirstEcsCluster'); app.run(); - diff --git a/typescript/ecs/ecs-load-balanced-service/index.ts b/typescript/ecs/ecs-load-balanced-service/index.ts index d34063724d..c251a14e96 100644 --- a/typescript/ecs/ecs-load-balanced-service/index.ts +++ b/typescript/ecs/ecs-load-balanced-service/index.ts @@ -10,7 +10,7 @@ class BonjourECS extends cdk.Stack { // a separate stack and import it here. We then have two stacks to // deploy, but VPC creation is slow so we'll only have to do that once // and can iterate quickly on consuming stacks. Not doing that for now. - const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 2 }); + const vpc = new ec2.Vpc(this, 'MyVpc', { maxAZs: 2 }); const cluster = new ecs.Cluster(this, 'Ec2Cluster', { vpc }); cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') diff --git a/typescript/ecs/ecs-service-with-advanced-alb-config/index.ts b/typescript/ecs/ecs-service-with-advanced-alb-config/index.ts index 9d1d1eb145..20c04bbcda 100644 --- a/typescript/ecs/ecs-service-with-advanced-alb-config/index.ts +++ b/typescript/ecs/ecs-service-with-advanced-alb-config/index.ts @@ -7,7 +7,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-ecs-integ-ecs'); // Create a cluster -const vpc = new ec2.VpcNetwork(stack, 'Vpc', { maxAZs: 2 }); +const vpc = new ec2.Vpc(stack, 'Vpc', { maxAZs: 2 }); const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); cluster.addCapacity('DefaultAutoScalingGroup', { diff --git a/typescript/ecs/ecs-service-with-logging/index.ts b/typescript/ecs/ecs-service-with-logging/index.ts index dec15cd20b..eb247c8ccf 100644 --- a/typescript/ecs/ecs-service-with-logging/index.ts +++ b/typescript/ecs/ecs-service-with-logging/index.ts @@ -6,7 +6,7 @@ class WillkommenECS extends cdk.Stack { constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { super(scope, id, props); - const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 2 }); + const vpc = new ec2.Vpc(this, 'MyVpc', { maxAZs: 2 }); const cluster = new ecs.Cluster(this, 'Ec2Cluster', { vpc }); cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') diff --git a/typescript/ecs/ecs-service-with-task-networking/index.ts b/typescript/ecs/ecs-service-with-task-networking/index.ts index 1077054ab8..a690bf8b34 100644 --- a/typescript/ecs/ecs-service-with-task-networking/index.ts +++ b/typescript/ecs/ecs-service-with-task-networking/index.ts @@ -8,7 +8,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'ec2-service-with-task-networking'); // Create the cluster -const vpc = new ec2.VpcNetwork(stack, 'Vpc', { maxAZs: 2 }); +const vpc = new ec2.Vpc(stack, 'Vpc', { maxAZs: 2 }); const cluster = new ecs.Cluster(stack, 'awsvpc-ecs-demo-cluster', { vpc }); cluster.addCapacity('DefaultAutoScalingGroup', { @@ -47,4 +47,4 @@ new ecs.Ec2Service(stack, 'awsvpc-ecs-demo-service', { securityGroup, }); -app.run(); \ No newline at end of file +app.run(); diff --git a/typescript/ecs/ecs-service-with-task-placement/index.ts b/typescript/ecs/ecs-service-with-task-placement/index.ts index c840caf0fc..11b125bbc0 100644 --- a/typescript/ecs/ecs-service-with-task-placement/index.ts +++ b/typescript/ecs/ecs-service-with-task-placement/index.ts @@ -6,7 +6,7 @@ const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-ecs-integ-ecs'); // Create a cluster -const vpc = new ec2.VpcNetwork(stack, 'Vpc', { maxAZs: 2 }); +const vpc = new ec2.Vpc(stack, 'Vpc', { maxAZs: 2 }); const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); cluster.addCapacity('DefaultAutoScalingGroup', { diff --git a/typescript/ecs/fargate-load-balanced-service/index.ts b/typescript/ecs/fargate-load-balanced-service/index.ts index b3d5b1130c..cb04ad3964 100644 --- a/typescript/ecs/fargate-load-balanced-service/index.ts +++ b/typescript/ecs/fargate-load-balanced-service/index.ts @@ -8,7 +8,7 @@ class BonjourFargate extends cdk.Stack { // Create VPC and Fargate Cluster // NOTE: Limit AZs to avoid reaching resource quotas - const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 2 }); + const vpc = new ec2.Vpc(this, 'MyVpc', { maxAZs: 2 }); const cluster = new ecs.Cluster(this, 'Cluster', { vpc }); // Instantiate Fargate Service with just cluster and image diff --git a/typescript/ecs/fargate-service-with-auto-scaling/index.ts b/typescript/ecs/fargate-service-with-auto-scaling/index.ts index 734c5ac8af..64c97b5029 100644 --- a/typescript/ecs/fargate-service-with-auto-scaling/index.ts +++ b/typescript/ecs/fargate-service-with-auto-scaling/index.ts @@ -7,7 +7,7 @@ class AutoScalingFargateService extends cdk.Stack { super(scope, id, props); // Create a cluster - const vpc = new ec2.VpcNetwork(this, 'Vpc', { maxAZs: 2 }); + const vpc = new ec2.Vpc(this, 'Vpc', { maxAZs: 2 }); const cluster = new ecs.Cluster(this, 'fargate-service-autoscaling', { vpc }); // Create Fargate Service diff --git a/typescript/ecs/fargate-service-with-local-image/index.ts b/typescript/ecs/fargate-service-with-local-image/index.ts index b355cd4848..c8cc169885 100644 --- a/typescript/ecs/fargate-service-with-local-image/index.ts +++ b/typescript/ecs/fargate-service-with-local-image/index.ts @@ -8,7 +8,7 @@ const stack = new cdk.Stack(app, 'FargateServiceWithLocalImage'); // Create VPC and Fargate Cluster // NOTE: Limit AZs to avoid reaching resource quotas -const vpc = new ec2.VpcNetwork(stack, 'MyVpc', { maxAZs: 2 }); +const vpc = new ec2.Vpc(stack, 'MyVpc', { maxAZs: 2 }); const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); // Instantiate Fargate Service with a cluster and a local image that gets diff --git a/typescript/ecs/fargate-service-with-logging/index.ts b/typescript/ecs/fargate-service-with-logging/index.ts index 0c39089028..b49212d19f 100644 --- a/typescript/ecs/fargate-service-with-logging/index.ts +++ b/typescript/ecs/fargate-service-with-logging/index.ts @@ -6,7 +6,7 @@ class WillkommenFargate extends cdk.Stack { constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { super(scope, id, props); - const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 2 }); + const vpc = new ec2.Vpc(this, 'MyVpc', { maxAZs: 2 }); const cluster = new ecs.Cluster(this, 'Ec2Cluster', { vpc }); // create a task definition with CloudWatch Logs diff --git a/typescript/resource-overrides/index.ts b/typescript/resource-overrides/index.ts index a20e8c66d7..9701bc715f 100644 --- a/typescript/resource-overrides/index.ts +++ b/typescript/resource-overrides/index.ts @@ -86,7 +86,7 @@ class ResourceOverridesExample extends cdk.Stack { bucketResource.addDeletionOverride('Metadata'); bucketResource.addPropertyDeletionOverride('CorsConfiguration.Bar'); - const vpc = new ec2.VpcNetwork(this, 'VPC', { maxAZs: 1 }); + const vpc = new ec2.Vpc(this, 'VPC', { maxAZs: 1 }); const asg = new autoscaling.AutoScalingGroup(this, 'ASG', { instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.XLarge), machineImage: new ec2.AmazonLinuxImage(), From 103f47d5e4a2e9384a450c12688ac3f2da5e0c42 Mon Sep 17 00:00:00 2001 From: Aleksandar Simovic Date: Mon, 27 May 2019 14:10:42 +0200 Subject: [PATCH 05/11] fixing ECS Placement Constraint distinctInstances() method --- typescript/ecs/ecs-service-with-task-placement/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/typescript/ecs/ecs-service-with-task-placement/index.ts b/typescript/ecs/ecs-service-with-task-placement/index.ts index 11b125bbc0..6e49906096 100644 --- a/typescript/ecs/ecs-service-with-task-placement/index.ts +++ b/typescript/ecs/ecs-service-with-task-placement/index.ts @@ -1,6 +1,7 @@ import ecs = require('@aws-cdk/aws-ecs'); import ec2 = require('@aws-cdk/aws-ec2'); import cdk = require('@aws-cdk/cdk'); +import { PlacementConstraint } from '@aws-cdk/aws-ecs'; const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-ecs-integ-ecs'); @@ -16,9 +17,7 @@ cluster.addCapacity('DefaultAutoScalingGroup', { // Create Task Definition with placement constraint const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef', { placementConstraints: [ - { - type: ecs.PlacementConstraintType.DistinctInstance - } + PlacementConstraint.distinctInstances() ] }); From 04e0c10b7c7baaf35273509aa27ad095201bf208 Mon Sep 17 00:00:00 2001 From: Aleksandar Simovic Date: Mon, 27 May 2019 14:15:13 +0200 Subject: [PATCH 06/11] fixing the loadBalancer.dnsName to loadBalancer.loadBalancerDnsName --- typescript/ecs/ecs-load-balanced-service/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/ecs/ecs-load-balanced-service/index.ts b/typescript/ecs/ecs-load-balanced-service/index.ts index c251a14e96..3f3cc64f83 100644 --- a/typescript/ecs/ecs-load-balanced-service/index.ts +++ b/typescript/ecs/ecs-load-balanced-service/index.ts @@ -24,7 +24,7 @@ class BonjourECS extends cdk.Stack { }); // Output the DNS where you can access your service - new cdk.CfnOutput(this, 'LoadBalancerDNS', { value: ecsService.loadBalancer.dnsName }); + new cdk.CfnOutput(this, 'LoadBalancerDNS', { value: ecsService.loadBalancer.loadBalancerDnsName }); } } From 60e38084eb0adb9ab7d8edce56af0dd7ba3bfd4e Mon Sep 17 00:00:00 2001 From: Aleksandar Simovic Date: Mon, 27 May 2019 14:20:12 +0200 Subject: [PATCH 07/11] fixing all of the loadBalancer instances --- typescript/ecs/ecs-service-with-advanced-alb-config/index.ts | 2 +- typescript/ecs/fargate-load-balanced-service/index.ts | 2 +- typescript/ecs/fargate-service-with-auto-scaling/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/typescript/ecs/ecs-service-with-advanced-alb-config/index.ts b/typescript/ecs/ecs-service-with-advanced-alb-config/index.ts index 20c04bbcda..c4c1635040 100644 --- a/typescript/ecs/ecs-service-with-advanced-alb-config/index.ts +++ b/typescript/ecs/ecs-service-with-advanced-alb-config/index.ts @@ -52,6 +52,6 @@ listener.addTargets('ECS', { } }); -new cdk.CfnOutput(stack, 'LoadBalancerDNS', { value: lb.dnsName, }); +new cdk.CfnOutput(stack, 'LoadBalancerDNS', { value: lb.loadBalancerDnsName, }); app.run(); diff --git a/typescript/ecs/fargate-load-balanced-service/index.ts b/typescript/ecs/fargate-load-balanced-service/index.ts index cb04ad3964..a656bf6201 100644 --- a/typescript/ecs/fargate-load-balanced-service/index.ts +++ b/typescript/ecs/fargate-load-balanced-service/index.ts @@ -18,7 +18,7 @@ class BonjourFargate extends cdk.Stack { }); // Output the DNS where you can access your service - new cdk.CfnOutput(this, 'LoadBalancerDNS', { value: fargateService.loadBalancer.dnsName }); + new cdk.CfnOutput(this, 'LoadBalancerDNS', { value: fargateService.loadBalancer.loadBalancerDnsName }); } } diff --git a/typescript/ecs/fargate-service-with-auto-scaling/index.ts b/typescript/ecs/fargate-service-with-auto-scaling/index.ts index 64c97b5029..cb1d57aa28 100644 --- a/typescript/ecs/fargate-service-with-auto-scaling/index.ts +++ b/typescript/ecs/fargate-service-with-auto-scaling/index.ts @@ -24,7 +24,7 @@ class AutoScalingFargateService extends cdk.Stack { scaleOutCooldownSec: 60 }); - new cdk.CfnOutput(this, 'LoadBalancerDNS', { value: fargateService.loadBalancer.dnsName, }); + new cdk.CfnOutput(this, 'LoadBalancerDNS', { value: fargateService.loadBalancer.loadBalancerDnsName, }); } } From 80fd39a17ed468e936f1797c7583e5dd419a5647 Mon Sep 17 00:00:00 2001 From: Aleksandar Simovic Date: Mon, 27 May 2019 14:26:41 +0200 Subject: [PATCH 08/11] fixing a typo --- typescript/ecs/cluster/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/ecs/cluster/index.ts b/typescript/ecs/cluster/index.ts index 425e8651fa..5152d21447 100644 --- a/typescript/ecs/cluster/index.ts +++ b/typescript/ecs/cluster/index.ts @@ -8,7 +8,7 @@ class ECSCluster extends cdk.Stack { constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { super(scope, id, props); - const vpc = new ec2.VPC(this, 'MyVpc', { maxAZs: 2 }); + const vpc = new ec2.Vpc(this, 'MyVpc', { maxAZs: 2 }); const asg = new autoscaling.AutoScalingGroup(this, 'MyFleet', { instanceType: new InstanceType("t2.xlarge"), From a406aed668455da075f7c365713a81824c5c847b Mon Sep 17 00:00:00 2001 From: Aleksandar Simovic Date: Mon, 27 May 2019 15:16:16 +0200 Subject: [PATCH 09/11] fixing the step functions example --- typescript/stepfunctions-job-poller/index.ts | 7 ++++--- typescript/stepfunctions-job-poller/package.json | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/typescript/stepfunctions-job-poller/index.ts b/typescript/stepfunctions-job-poller/index.ts index 5d73f3b366..ffd7d19569 100644 --- a/typescript/stepfunctions-job-poller/index.ts +++ b/typescript/stepfunctions-job-poller/index.ts @@ -1,5 +1,6 @@ import cdk = require('@aws-cdk/cdk'); import sfn = require('@aws-cdk/aws-stepfunctions'); +import tasks = require('@aws-cdk/aws-stepfunctions-tasks'); class JobPollerStack extends cdk.Stack { constructor(scope: cdk.App, id: string, props: cdk.StackProps = {}) { @@ -9,12 +10,12 @@ class JobPollerStack extends cdk.Stack { const checkJobActivity = new sfn.Activity(this, 'CheckJob'); const submitJob = new sfn.Task(this, 'Submit Job', { - resource: submitJobActivity, + task: new tasks.InvokeActivity(submitJobActivity), resultPath: '$.guid', }); const waitX = new sfn.Wait(this, 'Wait X Seconds', { duration: sfn.WaitDuration.secondsPath('$.wait_time') }); const getStatus = new sfn.Task(this, 'Get Job Status', { - resource: checkJobActivity, + task: new tasks.InvokeActivity(checkJobActivity), inputPath: '$.guid', resultPath: '$.status', }); @@ -24,7 +25,7 @@ class JobPollerStack extends cdk.Stack { error: 'DescribeJob returned FAILED', }); const finalStatus = new sfn.Task(this, 'Get Final Job Status', { - resource: checkJobActivity, + task: new tasks.InvokeActivity(checkJobActivity), inputPath: '$.guid', }); diff --git a/typescript/stepfunctions-job-poller/package.json b/typescript/stepfunctions-job-poller/package.json index f1e6d6f6e0..0cd84be019 100644 --- a/typescript/stepfunctions-job-poller/package.json +++ b/typescript/stepfunctions-job-poller/package.json @@ -20,6 +20,7 @@ }, "dependencies": { "@aws-cdk/aws-stepfunctions": "*", + "@aws-cdk/aws-stepfunctions-tasks": "^0.32.0", "@aws-cdk/cdk": "*" } } From e8ffb2bd7452c5762c3c66cba2b41c9033117f6b Mon Sep 17 00:00:00 2001 From: Aleksandar Simovic Date: Mon, 27 May 2019 15:23:34 +0200 Subject: [PATCH 10/11] remove version dependency of aws-stepfunctions-tasks --- typescript/stepfunctions-job-poller/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/stepfunctions-job-poller/package.json b/typescript/stepfunctions-job-poller/package.json index 0cd84be019..9ebf9edc2e 100644 --- a/typescript/stepfunctions-job-poller/package.json +++ b/typescript/stepfunctions-job-poller/package.json @@ -20,7 +20,7 @@ }, "dependencies": { "@aws-cdk/aws-stepfunctions": "*", - "@aws-cdk/aws-stepfunctions-tasks": "^0.32.0", + "@aws-cdk/aws-stepfunctions-tasks": "*", "@aws-cdk/cdk": "*" } } From c5003caee0af95fc1c63c5f498033f849ef65718 Mon Sep 17 00:00:00 2001 From: Aleksandar Simovic Date: Fri, 31 May 2019 10:53:58 +0200 Subject: [PATCH 11/11] removing unused PlacementConstraint --- typescript/ecs/ecs-service-with-task-placement/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/typescript/ecs/ecs-service-with-task-placement/index.ts b/typescript/ecs/ecs-service-with-task-placement/index.ts index d4cee62cc7..cdc09ffc50 100644 --- a/typescript/ecs/ecs-service-with-task-placement/index.ts +++ b/typescript/ecs/ecs-service-with-task-placement/index.ts @@ -1,7 +1,6 @@ import ecs = require('@aws-cdk/aws-ecs'); import ec2 = require('@aws-cdk/aws-ec2'); import cdk = require('@aws-cdk/cdk'); -import { PlacementConstraint } from '@aws-cdk/aws-ecs'; const app = new cdk.App(); const stack = new cdk.Stack(app, 'aws-ecs-integ-ecs');