private createThingInstallerGroup()

in infra/stack/iot/thing-installer-stack.ts [25:64]


    private createThingInstallerGroup(groupName: string) {
        const lambdaBaseName: string = 'create-iot-thing-group';
        const lambdaName: string = `${this.projectPrefix}-${lambdaBaseName}`;

        const lambdaRole = new iam.Role(this, `${lambdaBaseName}Role`, {
            roleName: `${lambdaName}Role`,
            assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
            managedPolicies: [
                { managedPolicyArn: 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole' }
            ]
        });
        lambdaRole.addToPolicy(new iam.PolicyStatement({
            actions: [
                "iot:CreateThingGroup",
                "iot:DeleteThingGroup"
            ],
            effect: iam.Effect.ALLOW,
            resources: ['*']
        }));

        const func = new lambda.Function(this, lambdaBaseName, {
            functionName: `${lambdaName}Function`,
            code: lambda.Code.fromAsset('./codes/lambda/custom_iot_thing_group/src'),
            handler: 'handler.handle',
            timeout: cdk.Duration.seconds(120),
            runtime: lambda.Runtime.PYTHON_3_6,
            role: lambdaRole,
        });

        const provider = new cr.Provider(this, 'CreateIotGroupProvider', {
            onEventHandler: func
        });

        new cdk.CustomResource(this, `CreateIotGroupCustomResource`, {
            serviceToken: provider.serviceToken,
            properties: {
                ThingGroupName: groupName,
            }
        });
    }