constructor()

in packages/aws-rfdk/lib/deadline/lib/wait-for-stable-service.ts [46:100]


  constructor(scope: Construct, id: string, props: WaitForStableServiceProps) {
    super(scope, id);

    const lambdaRole = new Role(this, 'ECSWaitLambdaRole', {
      assumedBy: new ServicePrincipal('lambda.amazonaws.com'),
      managedPolicies: [
        ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole'),
      ],
      inlinePolicies: {
        describeServices: new PolicyDocument({
          statements: [
            new PolicyStatement({
              actions: [
                'ecs:DescribeServices',
              ],
              effect: Effect.ALLOW,
              resources: [props.service.cluster.clusterArn, props.service.serviceArn],
            }),
          ],
        }),
      },
    });

    const waitingFunction = new LambdaFunction(this, 'ECSWait', {
      role: lambdaRole,
      description: `Used by a WaitForStableService ${this.node.addr} to wait until ECS service becomes stable`,
      code: Code.fromAsset(path.join(__dirname, '..', '..', 'lambdas', 'nodejs'), {
      }),
      environment: {
        DEBUG: 'false',
      },
      runtime: Runtime.NODEJS_18_X,
      handler: 'wait-for-stable-service.wait',
      timeout: Duration.minutes(15),
      logRetention: RetentionDays.ONE_WEEK,
    });

    const properties: WaitForStableServiceResourceProps = {
      cluster: props.service.cluster.clusterArn,
      services: [props.service.serviceArn],
      forceRun: this.forceRun(),
    };

    const resource = new CustomResource(this, 'Default', {
      serviceToken: waitingFunction.functionArn,
      resourceType: 'Custom::RFDK_WaitForStableService',
      properties,
    });

    // Prevents a race during a stack-update.
    resource.node.addDependency(lambdaRole);
    resource.node.addDependency(props.service);

    this.node.defaultChild = resource;
  }