How to use the @aws-cdk/aws-ecs.NetworkMode function in @aws-cdk/aws-ecs

To help you get started, we’ve selected a few @aws-cdk/aws-ecs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cdk / packages / @aws-cdk / aws-stepfunctions-tasks / lib / run-ecs-ec2-task.ts View on Github external
}

    if (!props.taskDefinition.defaultContainer) {
      throw new Error('A TaskDefinition must have at least one essential container');
    }

    super({
      ...props,
      parameters: {
        LaunchType: 'EC2',
        PlacementConstraints: noEmpty(flatten((props.placementConstraints || []).map(c => c.toJson().map(uppercaseKeys)))),
        PlacementStrategy: noEmpty(flatten((props.placementStrategies || []).map(c => c.toJson().map(uppercaseKeys)))),
      }
    });

    if (props.taskDefinition.networkMode === ecs.NetworkMode.AWS_VPC) {
      this.configureAwsVpcNetworking(props.cluster.vpc, undefined, props.subnets, props.securityGroup);
    } else {
      // Either None, Bridge or Host networking. Copy SecurityGroup from ASG.
      validateNoNetworkingProps(props);
      this.connections.addSecurityGroup(...props.cluster.connections.securityGroups);
    }
  }
}
github aws / aws-cdk / packages / @aws-cdk / aws-events-targets / lib / ecs-task.ts View on Github external
}

    const arn = this.cluster.clusterArn;
    const role = singletonEventRole(this.taskDefinition, policyStatements);
    const containerOverrides = this.props.containerOverrides && this.props.containerOverrides
      .map(({ containerName, ...overrides }) => ({ name: containerName, ...overrides }));
    const input = { containerOverrides };
    const taskCount = this.taskCount;
    const taskDefinitionArn = this.taskDefinition.taskDefinitionArn;

    const subnetSelection = this.props.subnetSelection || { subnetType: ec2.SubnetType.PRIVATE };
    const assignPublicIp = subnetSelection.subnetType === ec2.SubnetType.PUBLIC ? 'ENABLED' : 'DISABLED';

    const baseEcsParameters = { taskCount, taskDefinitionArn };

    const ecsParameters: events.CfnRule.EcsParametersProperty = this.taskDefinition.networkMode === ecs.NetworkMode.AWS_VPC
      ? {
        ...baseEcsParameters,
        launchType: this.taskDefinition.isEc2Compatible ? 'EC2' : 'FARGATE',
        networkConfiguration: {
          awsVpcConfiguration: {
            subnets: this.props.cluster.vpc.selectSubnets(subnetSelection).subnetIds,
            assignPublicIp,
            securityGroups: this.securityGroup && [this.securityGroup.securityGroupId]
          }
        }
      }
      : baseEcsParameters;

    return {
      id: '',
      arn,