From 1467be2b6bc9f3b920aaff43caf6c1ac5d87d749 Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Tue, 25 Aug 2020 23:15:37 +0200 Subject: [PATCH 01/17] feat(appsync): add authenticationConfig to HttpDataSource, fixes #9934 --- .../@aws-cdk/aws-appsync/lib/data-source.ts | 31 +++++++++++++++++++ .../aws-appsync/lib/graphqlapi-base.ts | 15 +++++++-- .../aws-appsync/test/appsync-http.test.ts | 29 +++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/data-source.ts b/packages/@aws-cdk/aws-appsync/lib/data-source.ts index 04c617b12e5d0..f6bbe66bc13cf 100644 --- a/packages/@aws-cdk/aws-appsync/lib/data-source.ts +++ b/packages/@aws-cdk/aws-appsync/lib/data-source.ts @@ -203,6 +203,35 @@ export class DynamoDbDataSource extends BackedDataSource { } } +/** + * The authorization config in case the HTTP endpoint requires authorization + */ +export interface HttpDataSourceAuthorizationConfig { + /** + * The authorization type required by the HTTP endpoint + */ + readonly authorizationType: 'AWS_IAM'; + /** + * The IAM configuration required by the HTTP endpoint + */ + readonly awsIamConfig: HttpDataSourceIamConfig; +} + +/** + * The IAM configuration required by the HTTP endpoint + */ +export interface HttpDataSourceIamConfig { + /** + * The signing region for AWS IAM authorization + */ + readonly signingRegion: string; + + /** + * The signing service name for AWS IAM authorization + */ + readonly signingServiceName: string; +} + /** * Properties for an AppSync http datasource */ @@ -211,6 +240,7 @@ export interface HttpDataSourceProps extends BaseDataSourceProps { * The http endpoint */ readonly endpoint: string; + readonly authorizationConfig?: HttpDataSourceAuthorizationConfig; } /** @@ -221,6 +251,7 @@ export class HttpDataSource extends BaseDataSource { super(scope, id, props, { httpConfig: { endpoint: props.endpoint, + authorizationConfig: props.authorizationConfig }, type: 'HTTP', }); diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts index 2f357c142db91..96e07fc5aaee0 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts @@ -1,7 +1,7 @@ import { ITable } from '@aws-cdk/aws-dynamodb'; import { IFunction } from '@aws-cdk/aws-lambda'; import { CfnResource, IResource, Resource } from '@aws-cdk/core'; -import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource } from './data-source'; +import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource, HttpDataSourceAuthorizationConfig } from './data-source'; /** * Optional configuration for data sources @@ -22,6 +22,16 @@ export interface DataSourceOptions { readonly description?: string; } +/** + * Optional configuration for Http data sources + */ +export interface HttpDataSourceOptions extends DataSourceOptions { + /** + * The authorization config in case the HTTP endpoint requires authorization + */ + readonly authorizationConfig?: HttpDataSourceAuthorizationConfig; +} + /** * Interface for GraphQL */ @@ -140,12 +150,13 @@ export abstract class GraphqlApiBase extends Resource implements IGraphqlApi { * @param endpoint The http endpoint * @param options The optional configuration for this data source */ - public addHttpDataSource(id: string, endpoint: string, options?: DataSourceOptions): HttpDataSource { + public addHttpDataSource(id: string, endpoint: string, options?: HttpDataSourceOptions): HttpDataSource { return new HttpDataSource(this, id, { api: this, endpoint, name: options?.name, description: options?.description, + authorizationConfig: options?.authorizationConfig }); } diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts index eac1415be5a67..50e2fb8a9d6ae 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts @@ -58,6 +58,35 @@ describe('Http Data Source configuration', () => { }); }); + test('appsync configures name, authorizationConfig correctly', () => { + // WHEN + api.addHttpDataSource('ds', endpoint, { + name: 'custom', + description: 'custom description', + authorizationConfig: { + authorizationType: 'AWS_IAM', + awsIamConfig: { + signingRegion: 'us-east-1', + signingServiceName: 'states' + } + } + }); + + // THEN + expect(stack).toHaveResourceLike('AWS::AppSync::DataSource', { + Type: 'HTTP', + Name: 'custom', + Description: 'custom description', + AuthorizationConfig: { + authorizationType: 'AWS_IAM', + awsIamConfig: { + signingRegion: 'us-east-1', + signingServiceName: 'states' + } + } + }); + }) + test('appsync errors when creating multiple http data sources with no configuration', () => { // THEN expect(() => { From eab93cff1c69a4065e28851d35eb1e24b0fb2e30 Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Wed, 26 Aug 2020 09:01:33 +0200 Subject: [PATCH 02/17] Update packages/@aws-cdk/aws-appsync/lib/data-source.ts Co-authored-by: Bryan Pan --- packages/@aws-cdk/aws-appsync/lib/data-source.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/data-source.ts b/packages/@aws-cdk/aws-appsync/lib/data-source.ts index f6bbe66bc13cf..f80cd6b589603 100644 --- a/packages/@aws-cdk/aws-appsync/lib/data-source.ts +++ b/packages/@aws-cdk/aws-appsync/lib/data-source.ts @@ -220,7 +220,7 @@ export interface HttpDataSourceAuthorizationConfig { /** * The IAM configuration required by the HTTP endpoint */ -export interface HttpDataSourceIamConfig { +export interface AwsIamConfig { /** * The signing region for AWS IAM authorization */ @@ -281,4 +281,4 @@ export class LambdaDataSource extends BackedDataSource { }); props.lambdaFunction.grantInvoke(this); } -} \ No newline at end of file +} From a594a35e07cd7f33034d91209019bc00ebc421e5 Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Wed, 26 Aug 2020 09:01:44 +0200 Subject: [PATCH 03/17] Update packages/@aws-cdk/aws-appsync/lib/data-source.ts Co-authored-by: Bryan Pan --- packages/@aws-cdk/aws-appsync/lib/data-source.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/data-source.ts b/packages/@aws-cdk/aws-appsync/lib/data-source.ts index f80cd6b589603..ceb1a49b76b36 100644 --- a/packages/@aws-cdk/aws-appsync/lib/data-source.ts +++ b/packages/@aws-cdk/aws-appsync/lib/data-source.ts @@ -240,7 +240,7 @@ export interface HttpDataSourceProps extends BaseDataSourceProps { * The http endpoint */ readonly endpoint: string; - readonly authorizationConfig?: HttpDataSourceAuthorizationConfig; + readonly authorizationConfig?: AwsIamConfig; } /** From dbbe4bff8feda4ca317c43a2f0fbc6ee626da33c Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Wed, 26 Aug 2020 10:31:11 +0200 Subject: [PATCH 04/17] feat(appsync): add example of http data source to the readme --- packages/@aws-cdk/aws-appsync/README.md | 85 ++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-appsync/README.md b/packages/@aws-cdk/aws-appsync/README.md index 96d0ce93d1879..21b684d485741 100644 --- a/packages/@aws-cdk/aws-appsync/README.md +++ b/packages/@aws-cdk/aws-appsync/README.md @@ -18,8 +18,10 @@ APIs that use GraphQL. ### Example +#### DynamoDB Data source example + Example of a GraphQL API with `AWS_IAM` authorization resolving into a DynamoDb -backend data source. +backend data source. GraphQL schema file `schema.graphql`: @@ -83,6 +85,87 @@ demoDS.createResolver({ }); ``` +#### Http data source example. Integrating SterFunctions workflow. +GraphQL schema file `schema.graphql`: + +```gql +type job { + id: String! + version: String! +} + +input DemoInput { + version: String! +} + +type Mutation { + callStepFunction(input: DemoInput!): job +} +``` + +GraphQL request mapping template `request.vtl`: + +``` +{ + "version": "2018-05-29", + "method": "POST", + "resourcePath": "/", + "params": { + "headers": { + "content-type": "application/x-amz-json-1.0", + "x-amz-target":"AWSStepFunctions.StartExecution" + }, + "body": { + "stateMachineArn": "", + "input": "{ \"id\": \"$context.arguments.id\" }" + } + } +} +``` + +GraphQL request mapping template `response.vtl`: + +``` +{ + "id": "${context.result.id}" +} +``` + +CDK stack file `app-stack.ts`: + +```ts +import * as appsync from '@aws-cdk/aws-appsync'; + +const api = new appsync.GraphQLApi(scope, 'id', { + name: 'api', + schemaDefinition: SchemaDefinition.FILE, + schemaDefinitionFile: 'schema.graphql' +}); + +const httpDs = api.addHttpDataSource( + 'ds', + 'https://states.amazonaws.com', + { + name: 'httpDsWithStepF', + description: 'from appsync to StepFunctions Workflow', + authorizationConfig: { + authorizationType: 'AWS_IAM', + awsIamConfig: { + signingRegion: 'us-east-1', + signingServiceName: 'states' + } + } + } +); + +httpDs.createResolver({ + typeName: 'Mutation', + fieldName: 'callStepFunction', + requestMappingTemplate: MappingTemplate.fromFile('request.vtl'), + responseMappingTemplate: MappingTemplate.fromFile('response.vtl') +}); +``` + ## Imports Any GraphQL Api that has been created outside the stack can be imported from From 4500ce804f4f71a062f7155c7fc21a9966a3a799 Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Wed, 26 Aug 2020 10:32:05 +0200 Subject: [PATCH 05/17] feat(appsync): AuthorizationConfig along with Cfn definition --- .../@aws-cdk/aws-appsync/lib/data-source.ts | 28 +++++++++---------- .../aws-appsync/lib/graphqlapi-base.ts | 4 +-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/data-source.ts b/packages/@aws-cdk/aws-appsync/lib/data-source.ts index ceb1a49b76b36..38c65a3e5fd60 100644 --- a/packages/@aws-cdk/aws-appsync/lib/data-source.ts +++ b/packages/@aws-cdk/aws-appsync/lib/data-source.ts @@ -206,30 +206,30 @@ export class DynamoDbDataSource extends BackedDataSource { /** * The authorization config in case the HTTP endpoint requires authorization */ -export interface HttpDataSourceAuthorizationConfig { +export interface AwsIamConfig { /** * The authorization type required by the HTTP endpoint */ readonly authorizationType: 'AWS_IAM'; /** - * The IAM configuration required by the HTTP endpoint + * The IAM signing configuration required by the HTTP endpoint */ - readonly awsIamConfig: HttpDataSourceIamConfig; + readonly awsIamConfig: AwsIamConfigSigning; } /** - * The IAM configuration required by the HTTP endpoint + * The IAM signing config in case the HTTP endpoint requires authorization */ -export interface AwsIamConfig { - /** - * The signing region for AWS IAM authorization - */ - readonly signingRegion: string; - - /** - * The signing service name for AWS IAM authorization - */ - readonly signingServiceName: string; +export interface AwsIamConfigSigning { + /** + * The signing region for AWS IAM authorization + */ + readonly signingRegion: string; + + /** + * The signing service name for AWS IAM authorization + */ + readonly signingServiceName: string; } /** diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts index 96e07fc5aaee0..97073a0d462d3 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts @@ -1,7 +1,7 @@ import { ITable } from '@aws-cdk/aws-dynamodb'; import { IFunction } from '@aws-cdk/aws-lambda'; import { CfnResource, IResource, Resource } from '@aws-cdk/core'; -import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource, HttpDataSourceAuthorizationConfig } from './data-source'; +import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource, AwsIamConfig } from './data-source'; /** * Optional configuration for data sources @@ -29,7 +29,7 @@ export interface HttpDataSourceOptions extends DataSourceOptions { /** * The authorization config in case the HTTP endpoint requires authorization */ - readonly authorizationConfig?: HttpDataSourceAuthorizationConfig; + readonly authorizationConfig?: AwsIamConfig; } /** From 442828b42be99dc8797e972289b73a01ba396619 Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Fri, 28 Aug 2020 04:56:25 +0200 Subject: [PATCH 06/17] Update packages/@aws-cdk/aws-appsync/README.md Co-authored-by: Bryan Pan --- packages/@aws-cdk/aws-appsync/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/README.md b/packages/@aws-cdk/aws-appsync/README.md index 9074813de8bd5..a21ba8bdcc720 100644 --- a/packages/@aws-cdk/aws-appsync/README.md +++ b/packages/@aws-cdk/aws-appsync/README.md @@ -137,8 +137,7 @@ import * as appsync from '@aws-cdk/aws-appsync'; const api = new appsync.GraphQLApi(scope, 'id', { name: 'api', - schemaDefinition: SchemaDefinition.FILE, - schemaDefinitionFile: 'schema.graphql' + schema: appsync.Schema.fromFile(join(__dirname, 'schema.graphql)) }); const httpDs = api.addHttpDataSource( @@ -647,4 +646,3 @@ You can create Object Types in three ways: }); ``` > This method provides easy use and is ideal for smaller projects. - From 8c68f3cf771f542c4fcad6a55f0a955df5f9098a Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Fri, 28 Aug 2020 05:43:08 +0200 Subject: [PATCH 07/17] Update packages/@aws-cdk/aws-appsync/README.md Co-authored-by: Bryan Pan --- packages/@aws-cdk/aws-appsync/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-appsync/README.md b/packages/@aws-cdk/aws-appsync/README.md index a21ba8bdcc720..74e0ea9db8072 100644 --- a/packages/@aws-cdk/aws-appsync/README.md +++ b/packages/@aws-cdk/aws-appsync/README.md @@ -18,7 +18,7 @@ APIs that use GraphQL. ### Example -#### DynamoDB Data source example +#### DynamoDB Example of a GraphQL API with `AWS_IAM` authorization resolving into a DynamoDb backend data source. From beb02691e0187180b4042ead4562a66142cd6bdc Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Fri, 28 Aug 2020 05:43:17 +0200 Subject: [PATCH 08/17] Update packages/@aws-cdk/aws-appsync/README.md Co-authored-by: Bryan Pan --- packages/@aws-cdk/aws-appsync/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-appsync/README.md b/packages/@aws-cdk/aws-appsync/README.md index 74e0ea9db8072..bb0007ab640cd 100644 --- a/packages/@aws-cdk/aws-appsync/README.md +++ b/packages/@aws-cdk/aws-appsync/README.md @@ -84,7 +84,7 @@ demoDS.createResolver({ }); ``` -#### Http data source example. Integrating SterFunctions workflow. +#### HTTP Endpoints GraphQL schema file `schema.graphql`: ```gql From b289be5f29bab99e37cbb3e573a07fb90fc2c464 Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Fri, 28 Aug 2020 05:49:53 +0200 Subject: [PATCH 09/17] feat(appsync): Update readme (position of the Import header) --- packages/@aws-cdk/aws-appsync/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/README.md b/packages/@aws-cdk/aws-appsync/README.md index bb0007ab640cd..9de7f3d08b8c8 100644 --- a/packages/@aws-cdk/aws-appsync/README.md +++ b/packages/@aws-cdk/aws-appsync/README.md @@ -164,7 +164,6 @@ httpDs.createResolver({ }); ``` -## Imports ### Schema Every GraphQL Api needs a schema to define the Api. CDK offers `appsync.Schema` @@ -211,7 +210,7 @@ const api = appsync.GraphQLApi(stack, 'api', { }); ``` - +## Imports Any GraphQL Api that has been created outside the stack can be imported from another stack into your CDK app. Utilizing the `fromXxx` function, you have the ability to add data sources and resolvers through a `IGraphQLApi` interface. From e6250b2f4f4bf45b4f398dd9dbb0c70550f81cf3 Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Fri, 28 Aug 2020 06:48:30 +0200 Subject: [PATCH 10/17] feat(appsync) remove nested construction of awsIamConfig in HttpDataSource --- .../@aws-cdk/aws-appsync/lib/data-source.ts | 53 +++++++++++-------- .../aws-appsync/lib/graphqlapi-base.ts | 2 +- .../aws-appsync/test/appsync-http.test.ts | 6 +-- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/data-source.ts b/packages/@aws-cdk/aws-appsync/lib/data-source.ts index 38c65a3e5fd60..4a6c4042ec6dd 100644 --- a/packages/@aws-cdk/aws-appsync/lib/data-source.ts +++ b/packages/@aws-cdk/aws-appsync/lib/data-source.ts @@ -212,24 +212,14 @@ export interface AwsIamConfig { */ readonly authorizationType: 'AWS_IAM'; /** - * The IAM signing configuration required by the HTTP endpoint + * The signing region for AWS IAM authorization */ - readonly awsIamConfig: AwsIamConfigSigning; -} + readonly signingRegion: string; -/** - * The IAM signing config in case the HTTP endpoint requires authorization - */ -export interface AwsIamConfigSigning { - /** - * The signing region for AWS IAM authorization - */ - readonly signingRegion: string; - - /** - * The signing service name for AWS IAM authorization - */ - readonly signingServiceName: string; + /** + * The signing service name for AWS IAM authorization + */ + readonly signingServiceName: string; } /** @@ -248,13 +238,30 @@ export interface HttpDataSourceProps extends BaseDataSourceProps { */ export class HttpDataSource extends BaseDataSource { constructor(scope: Construct, id: string, props: HttpDataSourceProps) { - super(scope, id, props, { - httpConfig: { - endpoint: props.endpoint, - authorizationConfig: props.authorizationConfig - }, - type: 'HTTP', - }); + if (!props.authorizationConfig) { + super(scope, id, props, { + httpConfig: { + endpoint: props.endpoint + }, + type: 'HTTP', + }) + } else { + const authConfig = props.authorizationConfig + super(scope, id, props, { + httpConfig: { + endpoint: props.endpoint, + authorizationConfig: { + authorizationType: authConfig.authorizationType, + awsIamConfig: { + signingRegion: authConfig.signingRegion, + signingServiceName: authConfig.signingServiceName + } + + } + }, + type: 'HTTP', + }) + } } } diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts index 97073a0d462d3..7a92dc6bfa6d6 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts @@ -86,7 +86,7 @@ export interface IGraphqlApi extends IResource { * @param lambdaFunction The Lambda function to call to interact with this data source * @param options The optional configuration for this data source */ - addLambdaDataSource(id: string, lambdaFunction: IFunction, options?: DataSourceOptions): LambdaDataSource; + addLambdaDataSource(id: string, lambdaFunction: IFunction, options?: HttpDataSourceOptions): LambdaDataSource; /** * Add schema dependency if not imported diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts index 429b3c6f6c901..b75800c7cc6a4 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts @@ -64,10 +64,8 @@ describe('Http Data Source configuration', () => { description: 'custom description', authorizationConfig: { authorizationType: 'AWS_IAM', - awsIamConfig: { - signingRegion: 'us-east-1', - signingServiceName: 'states' - } + signingRegion: 'us-east-1', + signingServiceName: 'states' } }); From 08b42d932861487046938b5d2e41a688e247df4e Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Fri, 28 Aug 2020 22:57:39 +0200 Subject: [PATCH 11/17] feat(appsync) fix options bug addHttpDataSource, addLambdaDataSource --- packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts index 7a92dc6bfa6d6..dd82787bfc9d0 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts @@ -77,7 +77,7 @@ export interface IGraphqlApi extends IResource { * @param endpoint The http endpoint * @param options The optional configuration for this data source */ - addHttpDataSource(id: string, endpoint: string, options?: DataSourceOptions): HttpDataSource; + addHttpDataSource(id: string, endpoint: string, options?: HttpDataSourceOptions): HttpDataSource; /** * add a new Lambda data source to this API @@ -86,7 +86,7 @@ export interface IGraphqlApi extends IResource { * @param lambdaFunction The Lambda function to call to interact with this data source * @param options The optional configuration for this data source */ - addLambdaDataSource(id: string, lambdaFunction: IFunction, options?: HttpDataSourceOptions): LambdaDataSource; + addLambdaDataSource(id: string, lambdaFunction: IFunction, options?: DataSourceOptions): LambdaDataSource; /** * Add schema dependency if not imported From 9be1c7c90b3b974575c5d4d97875e801433b7d51 Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Sat, 29 Aug 2020 08:46:05 +0200 Subject: [PATCH 12/17] Update packages/@aws-cdk/aws-appsync/lib/data-source.ts thx! Co-authored-by: Bryan Pan --- .../@aws-cdk/aws-appsync/lib/data-source.ts | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/data-source.ts b/packages/@aws-cdk/aws-appsync/lib/data-source.ts index 4a6c4042ec6dd..871c4ef526c97 100644 --- a/packages/@aws-cdk/aws-appsync/lib/data-source.ts +++ b/packages/@aws-cdk/aws-appsync/lib/data-source.ts @@ -238,28 +238,17 @@ export interface HttpDataSourceProps extends BaseDataSourceProps { */ export class HttpDataSource extends BaseDataSource { constructor(scope: Construct, id: string, props: HttpDataSourceProps) { - if (!props.authorizationConfig) { - super(scope, id, props, { - httpConfig: { - endpoint: props.endpoint - }, - type: 'HTTP', - }) - } else { - const authConfig = props.authorizationConfig - super(scope, id, props, { - httpConfig: { - endpoint: props.endpoint, - authorizationConfig: { - authorizationType: authConfig.authorizationType, - awsIamConfig: { - signingRegion: authConfig.signingRegion, - signingServiceName: authConfig.signingServiceName - } - - } - }, - type: 'HTTP', + const authorizationConfig = props.authorizationConfig ? { + authorizationType: 'AWS_IAM', + awsIamConfig: props.authorizationConfig, + } : undefined; + + super(scope, id, props, { + httpConfig: { + endpoint: props.endpoint, + authorizationConfig, + }, + }); }) } } From f1a1145e581e65ec0aa355c43021a57c018afcd5 Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Sat, 29 Aug 2020 09:18:53 +0200 Subject: [PATCH 13/17] feat(appsync) fix it is not necessary to specify authorizationType in addHttpDataSource --- packages/@aws-cdk/aws-appsync/README.md | 7 ++----- packages/@aws-cdk/aws-appsync/lib/data-source.ts | 13 ++++--------- .../@aws-cdk/aws-appsync/test/appsync-http.test.ts | 1 - 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/README.md b/packages/@aws-cdk/aws-appsync/README.md index 577715016cf96..d481b183d5d48 100644 --- a/packages/@aws-cdk/aws-appsync/README.md +++ b/packages/@aws-cdk/aws-appsync/README.md @@ -147,11 +147,8 @@ const httpDs = api.addHttpDataSource( name: 'httpDsWithStepF', description: 'from appsync to StepFunctions Workflow', authorizationConfig: { - authorizationType: 'AWS_IAM', - awsIamConfig: { - signingRegion: 'us-east-1', - signingServiceName: 'states' - } + signingRegion: 'us-east-1', + signingServiceName: 'states' } } ); diff --git a/packages/@aws-cdk/aws-appsync/lib/data-source.ts b/packages/@aws-cdk/aws-appsync/lib/data-source.ts index 871c4ef526c97..368fadeb4ab96 100644 --- a/packages/@aws-cdk/aws-appsync/lib/data-source.ts +++ b/packages/@aws-cdk/aws-appsync/lib/data-source.ts @@ -207,10 +207,6 @@ export class DynamoDbDataSource extends BackedDataSource { * The authorization config in case the HTTP endpoint requires authorization */ export interface AwsIamConfig { - /** - * The authorization type required by the HTTP endpoint - */ - readonly authorizationType: 'AWS_IAM'; /** * The signing region for AWS IAM authorization */ @@ -244,13 +240,12 @@ export class HttpDataSource extends BaseDataSource { } : undefined; super(scope, id, props, { + type: 'HTTP', httpConfig: { endpoint: props.endpoint, - authorizationConfig, - }, - }); - }) - } + authorizationConfig + } + }) } } diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts index b75800c7cc6a4..e468f0b63db9f 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts @@ -63,7 +63,6 @@ describe('Http Data Source configuration', () => { name: 'custom', description: 'custom description', authorizationConfig: { - authorizationType: 'AWS_IAM', signingRegion: 'us-east-1', signingServiceName: 'states' } From 5e7d3af172e4ecd7084a019fe45c9653c28b397c Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Sun, 30 Aug 2020 07:24:49 +0200 Subject: [PATCH 14/17] feat(appsync) fix lint error --- .../@aws-cdk/aws-appsync/lib/data-source.ts | 25 +++++++++---------- .../aws-appsync/test/appsync-http.test.ts | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/data-source.ts b/packages/@aws-cdk/aws-appsync/lib/data-source.ts index 368fadeb4ab96..e88a3ea64e15a 100644 --- a/packages/@aws-cdk/aws-appsync/lib/data-source.ts +++ b/packages/@aws-cdk/aws-appsync/lib/data-source.ts @@ -226,7 +226,7 @@ export interface HttpDataSourceProps extends BaseDataSourceProps { * The http endpoint */ readonly endpoint: string; - readonly authorizationConfig?: AwsIamConfig; + readonly authorizationConfig?: AwsIamConfig; } /** @@ -234,18 +234,17 @@ export interface HttpDataSourceProps extends BaseDataSourceProps { */ export class HttpDataSource extends BaseDataSource { constructor(scope: Construct, id: string, props: HttpDataSourceProps) { - const authorizationConfig = props.authorizationConfig ? { - authorizationType: 'AWS_IAM', - awsIamConfig: props.authorizationConfig, - } : undefined; - - super(scope, id, props, { - type: 'HTTP', - httpConfig: { - endpoint: props.endpoint, - authorizationConfig - } - }) + const authorizationConfig = props.authorizationConfig ? { + authorizationType: 'AWS_IAM', + awsIamConfig: props.authorizationConfig, + } : undefined; + super(scope, id, props, { + type: 'HTTP', + httpConfig: { + endpoint: props.endpoint, + authorizationConfig, + }, + }); } } diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts index e468f0b63db9f..53db473a929bd 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts @@ -81,7 +81,7 @@ describe('Http Data Source configuration', () => { } } }); - }) + }); test('appsync errors when creating multiple http data sources with no configuration', () => { // THEN From 3268ff4e6e6a3e2089b4311ca2aa9cfc01b6c7c0 Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Sun, 30 Aug 2020 07:44:45 +0200 Subject: [PATCH 15/17] feat(appsync) fix lint error --- packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts | 2 +- .../@aws-cdk/aws-appsync/test/appsync-http.test.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts index dd82787bfc9d0..6fbd32145ed3b 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts @@ -156,7 +156,7 @@ export abstract class GraphqlApiBase extends Resource implements IGraphqlApi { endpoint, name: options?.name, description: options?.description, - authorizationConfig: options?.authorizationConfig + authorizationConfig: options?.authorizationConfig, }); } diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts index 53db473a929bd..7129f4e72f3c5 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts @@ -64,8 +64,8 @@ describe('Http Data Source configuration', () => { description: 'custom description', authorizationConfig: { signingRegion: 'us-east-1', - signingServiceName: 'states' - } + signingServiceName: 'states', + }, }); // THEN @@ -77,9 +77,9 @@ describe('Http Data Source configuration', () => { authorizationType: 'AWS_IAM', awsIamConfig: { signingRegion: 'us-east-1', - signingServiceName: 'states' - } - } + signingServiceName: 'states', + }, + }, }); }); From e33d77cc78dab4d822fde430402683dd18a6cb0f Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Sun, 30 Aug 2020 08:27:57 +0200 Subject: [PATCH 16/17] feat(appsync) fix lint error --- packages/@aws-cdk/aws-appsync/lib/data-source.ts | 7 +++++++ packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts | 2 ++ 2 files changed, 9 insertions(+) diff --git a/packages/@aws-cdk/aws-appsync/lib/data-source.ts b/packages/@aws-cdk/aws-appsync/lib/data-source.ts index e88a3ea64e15a..46a570d461fe2 100644 --- a/packages/@aws-cdk/aws-appsync/lib/data-source.ts +++ b/packages/@aws-cdk/aws-appsync/lib/data-source.ts @@ -226,6 +226,13 @@ export interface HttpDataSourceProps extends BaseDataSourceProps { * The http endpoint */ readonly endpoint: string; + + /** + * The authorization config in case the HTTP endpoint requires authorization + * + * @default - none + * + */ readonly authorizationConfig?: AwsIamConfig; } diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts index 6fbd32145ed3b..0525b51340fcd 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts @@ -28,6 +28,8 @@ export interface DataSourceOptions { export interface HttpDataSourceOptions extends DataSourceOptions { /** * The authorization config in case the HTTP endpoint requires authorization + * + * @default - none */ readonly authorizationConfig?: AwsIamConfig; } From 392bf1265be435780efadfe5e8036fb4aa2372c3 Mon Sep 17 00:00:00 2001 From: haruharuharuby Date: Sun, 30 Aug 2020 08:59:02 +0200 Subject: [PATCH 17/17] feat(appsync) fix lint unit test --- .../@aws-cdk/aws-appsync/test/appsync-http.test.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts index 7129f4e72f3c5..4ee50e0ce4b4e 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts @@ -73,11 +73,14 @@ describe('Http Data Source configuration', () => { Type: 'HTTP', Name: 'custom', Description: 'custom description', - AuthorizationConfig: { - authorizationType: 'AWS_IAM', - awsIamConfig: { - signingRegion: 'us-east-1', - signingServiceName: 'states', + HttpConfig: { + Endpoint: endpoint, + AuthorizationConfig: { + AuthorizationType: 'AWS_IAM', + AwsIamConfig: { + SigningRegion: 'us-east-1', + SigningServiceName: 'states', + }, }, }, });