This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private createApiAccessKey( | |
api: appsync.CfnGraphQLApi | |
): iam.CfnAccessKey { | |
const apiAccessGroup = this.createApiAccessGroup(api); | |
const apiAccessUser = this.createApiAccessUser(apiAccessGroup); | |
const name = 'ApiAccessKey'; | |
return new iam.CfnAccessKey(this, name, { | |
userName: apiAccessUser.userName | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private createApiAccessGroup( | |
api: appsync.CfnGraphQLApi | |
): iam.Group { | |
const name = 'ApiAccessGroup'; | |
const group = new iam.Group(this, name, { | |
groupName: name | |
}); | |
group.attachInlinePolicy(this.createApiAccessPolicy(api)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private creatGetOutputResolver( | |
api: appsync.CfnGraphQLApi, | |
schema: appsync.CfnGraphQLSchema, | |
outputDataSource: appsync.CfnDataSource | |
) { | |
const name = 'GetOutputResolver'; | |
const requestMappingTemplate = `{ | |
"version": "2017-02-28", | |
"operation": "Invoke", | |
"payload": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private createOutputDataSource( | |
api: appsync.CfnGraphQLApi, | |
outputLambda: lambda.Function, | |
): appsync.CfnDataSource { | |
const name = 'OutputDataSource'; | |
const invokeRole = this.createOutputLambdaInvokeRole(outputLambda); | |
const outputDataSource = new appsync.CfnDataSource(this, name, { | |
apiId: api.attrApiId, | |
name: name, | |
type: 'AWS_LAMBDA', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private createOutputLambdaInvokeRole( | |
outputLambda: lambda.Function | |
): iam.Role { | |
const name = 'OutputLambdaAppSyncInvokeRole'; | |
const invokeRole = new iam.Role(this, name, { | |
roleName: name, | |
assumedBy: new iam.ServicePrincipal('appsync.amazonaws.com') | |
}); | |
invokeRole.attachInlinePolicy(this.createOutputLambdaInvokePolicy(outputLambda)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private createOutputLambda(): lambda.Function { | |
const name = 'OutputLambda'; | |
return new lambda.Function(this, name, { | |
functionName: name, | |
runtime: lambda.Runtime.DOTNET_CORE_2_1, | |
code: lambda.Code.asset('../src/appsync/bin/Release/netcoreapp2.1/publish'), | |
handler: 'appsync::appsync.Function::FunctionHandler', | |
timeout: cdk.Duration.seconds(15) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Function | |
{ | |
public Output FunctionHandler(Input input, ILambdaContext context) | |
{ | |
return new Output | |
{ | |
Numbers = Enumerable.Repeat(input.Number, input.Count).ToArray() | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private createSchema( | |
api: appsync.CfnGraphQLApi | |
): appsync.CfnGraphQLSchema { | |
const name = 'Schema'; | |
const definition = ` | |
type Output { | |
Numbers: [Int!]! | |
} | |
type Query { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private createApi(): appsync.CfnGraphQLApi { | |
const name = 'Api'; | |
const cloudWatchLogsRoleArn = this.createApiCloudWatchRole().roleArn | |
return new appsync.CfnGraphQLApi(this, name, { | |
name: name, | |
authenticationType: 'AWS_IAM', | |
logConfig: { | |
fieldLogLevel: 'ERROR', | |
cloudWatchLogsRoleArn: cloudWatchLogsRoleArn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static createAccessKeyOutputs(scope: cdk.Construct, accessKey: iam.CfnAccessKey) { | |
new cdk.CfnOutput(scope, 'UserAccessKeyId', { | |
value: accessKey.ref | |
}); | |
new cdk.CfnOutput(scope, 'UserSecretAccessKey', { | |
value: accessKey.attrSecretAccessKey | |
}); | |
} | |
private static createS3BucketOutputs(scope: cdk.Construct, s3Bucket: s3.Bucket) { |