constructor()

in packages/aws-rfdk/lib/deadline/lib/spot-event-plugin-fleet.ts [462:538]


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

    this.defaultSubnets = !props.vpcSubnets;

    this.deadlineGroups = props.deadlineGroups.map(group => group.toLocaleLowerCase());
    this.deadlinePools = props.deadlinePools?.map(pool => pool.toLocaleLowerCase());
    this.validateProps(props);

    this.securityGroups = props.securityGroups ?? [ new SecurityGroup(this, 'SpotFleetSecurityGroup', { vpc: props.vpc }) ];
    this.connections = new Connections({ securityGroups: this.securityGroups });
    this.connections.allowToDefaultPort(props.renderQueue.endpoint);

    this.fleetInstanceRole = props.fleetInstanceRole ?? new Role(this, 'SpotFleetInstanceRole', {
      assumedBy: new ServicePrincipal('ec2.amazonaws.com'),
      managedPolicies: [
        ManagedPolicy.fromAwsManagedPolicyName('AWSThinkboxDeadlineSpotEventPluginWorkerPolicy'),
      ],
      description: `Spot Fleet instance role for ${id} in region ${Stack.of(scope).region}`,
    });

    this.instanceProfile = new CfnInstanceProfile(this, 'InstanceProfile', {
      roles: [this.fleetInstanceRole.roleName],
    });

    this.grantPrincipal = this.fleetInstanceRole;

    this.fleetRole = props.fleetRole ?? new Role(this, 'SpotFleetRole', {
      assumedBy: new ServicePrincipal('spotfleet.amazonaws.com'),
      managedPolicies: [
        ManagedPolicy.fromAwsManagedPolicyName('service-role/AmazonEC2SpotFleetTaggingRole'),
      ],
      description: `Spot Fleet role for ${id} in region ${Stack.of(scope).region}`,
    });

    this.blockDevices = props.blockDevices;
    this.subnets = props.vpc.selectSubnets(props.vpcSubnets ?? { subnetType: SubnetType.PRIVATE_WITH_EGRESS });
    this.instanceTypes = props.instanceTypes;
    this.allocationStrategy = props.allocationStrategy ?? SpotFleetAllocationStrategy.LOWEST_PRICE;
    this.maxCapacity = props.maxCapacity;
    this.validUntil = props.validUntil;
    this.keyName = props.keyName;
    this.context = props.context;

    const imageConfig = props.workerMachineImage.getImage(this);
    this.osType = imageConfig.osType;
    this.userData = props.userData ?? imageConfig.userData;
    this.machineImage = props.workerMachineImage;

    const workerConfig = new WorkerInstanceConfiguration(this, id, {
      worker: this,
      cloudWatchLogSettings: {
        logGroupPrefix: SpotEventPluginFleet.DEFAULT_LOG_GROUP_PREFIX,
        ...props.logGroupProps,
      },
      renderQueue: props.renderQueue,
      workerSettings: {
        groups: this.deadlineGroups,
        pools: this.deadlinePools,
        region: props.deadlineRegion,
      },
      userDataProvider: props.userDataProvider,
    });

    this.remoteControlPorts = Port.tcpRange(
      workerConfig.listenerPort,
      workerConfig.listenerPort + SpotEventPluginFleet.MAX_WORKERS_PER_HOST,
    );

    this.tags = new TagManager(TagType.KEY_VALUE, 'RFDK::SpotEventPluginFleet');

    // Tag deployed resources with RFDK meta-data
    tagConstruct(this);

    this.launchTemplate = this.createLaunchTemplate(props.trackInstancesWithResourceTracker ?? true);
    this._launchTemplateConfigs = this.createLaunchTemplateConfigs();
  }