All files p6namer.ts

100% Statements 12/12
100% Branches 0/0
100% Functions 1/1
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42  1x 1x 1x 1x 1x           1x   1x   1x   1x                   1x   1x       1x                
import type { Construct } from 'constructs'
import * as cdk from 'aws-cdk-lib'
import * as lambda from 'aws-cdk-lib/aws-lambda'
import * as lambdajs from 'aws-cdk-lib/aws-lambda-nodejs'
import * as cr from 'aws-cdk-lib/custom-resources'
import * as floyd from 'cdk-iam-floyd'
 
export interface IP6NamerProps {
  accountAlias: string
}
 
export class P6Namer extends cdk.Resource {
  constructor(scope: Construct, id: string, props: IP6NamerProps) {
    super(scope, id)
 
    const policy = new floyd.Statement.Iam().allow().toCreateAccountAlias()
 
    const onEvent = new lambdajs.NodejsFunction(this, 'p6namer', {
      runtime: lambda.Runtime.NODEJS_20_X,
      timeout: cdk.Duration.seconds(2),
      tracing: lambda.Tracing.ACTIVE,
      bundling: {
        minify: true,
        externalModules: ['aws-sdk'],
      },
    })
 
    onEvent.addToRolePolicy(policy)
 
    const provider = new cr.Provider(this, 'P6Namer/Provider', {
      onEventHandler: onEvent,
    })
 
    new cdk.CustomResource(this, 'P6Namer/CR', {
      serviceToken: provider.serviceToken,
      properties: {
        AccountAlias: props.accountAlias,
      },
    })
  }
}