From e44d15365b1e3e43d7e219f89ae7976fa31dff09 Mon Sep 17 00:00:00 2001 From: Duarte Nunes Date: Thu, 16 Apr 2020 00:14:38 -0300 Subject: [PATCH] feat(appsync): export configured API key If an AppSync API is configured with the API key authorization mode, then export it so it can be consumed as a stack output. Signed-off-by: Duarte Nunes --- packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index ec20f97b9841d..c2ce064d3d25a 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -193,8 +193,15 @@ export class GraphQLApi extends Construct { * underlying CFN schema resource */ public readonly schema: CfnGraphQLSchema; + /** + * the configured API key, if present + */ + public get apiKey(): string | undefined { + return this._apiKey; + } private api: CfnGraphQLApi; + private _apiKey?: string; constructor(scope: Construct, id: string, props: GraphQLApiProps) { super(scope, id); @@ -325,11 +332,12 @@ export class GraphQLApi extends Construct { } expires = Math.round(expires / 1000); } - new CfnApiKey(this, `${akConfig.apiKeyDesc || ''}ApiKey`, { + const key = new CfnApiKey(this, `${akConfig.apiKeyDesc || ''}ApiKey`, { expires, description: akConfig.apiKeyDesc, apiId: this.apiId, }); + this._apiKey = key.attrApiKey; return { authenticationType: 'API_KEY' }; } }