Skip to content

Instantly share code, notes, and snippets.

View mgjam's full-sized avatar

Milan Gatyás mgjam

View GitHub Profile
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
});
private createApiAccessGroup(
api: appsync.CfnGraphQLApi
): iam.Group {
const name = 'ApiAccessGroup';
const group = new iam.Group(this, name, {
groupName: name
});
group.attachInlinePolicy(this.createApiAccessPolicy(api));
private creatGetOutputResolver(
api: appsync.CfnGraphQLApi,
schema: appsync.CfnGraphQLSchema,
outputDataSource: appsync.CfnDataSource
) {
const name = 'GetOutputResolver';
const requestMappingTemplate = `{
"version": "2017-02-28",
"operation": "Invoke",
"payload": {
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',
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));
@mgjam
mgjam / 5-lambda.ts
Last active October 27, 2019 16:27
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)
});
@mgjam
mgjam / 5-lambda.cs
Last active October 27, 2019 16:28
public class Function
{
public Output FunctionHandler(Input input, ILambdaContext context)
{
return new Output
{
Numbers = Enumerable.Repeat(input.Number, input.Count).ToArray()
};
}
}
@mgjam
mgjam / 4-schema.ts
Last active October 27, 2019 15:55
private createSchema(
api: appsync.CfnGraphQLApi
): appsync.CfnGraphQLSchema {
const name = 'Schema';
const definition = `
type Output {
Numbers: [Int!]!
}
type Query {
@mgjam
mgjam / 4-api.ts
Last active October 27, 2019 15:55
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
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) {