Skip to content

Commit

Permalink
feat(appsync): export configured API key (#7380)
Browse files Browse the repository at this point in the history
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 <duarte@uma.ni>

Co-authored-by: Mitchell Valine <valinm@amazon.com>
  • Loading branch information
duarten and MrArnoldPalmer committed May 3, 2020
1 parent da7c508 commit fa8c13c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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' };
}
}
Expand Down

0 comments on commit fa8c13c

Please sign in to comment.