0.1.0 • Published 4 years ago
@stackspot/cdk-ecs v0.1.0
container-env-jsii-component
Component for managing an ECS cluster.
How to use
Below are all languages supported by the AWS CDK.
C
Install the dependency:
dotnet add package StackSpot.Cdk.EcsImport the construct into your project, for example:
using Amazon.CDK;
using Amazon.CDK.AWS.EC2;
using Constructs;
using StackSpot.Cdk.Ecs;
namespace MyStack
{
    public class MyStack : Stack
    {
        internal MyStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            Vpc vpc = new Vpc(this, "VPC");
            Ecs ecs = new Ecs(this, "MyEcs", new EcsCreateProps{
                ClusterName = "MyCluster",
                Vpc = vpc
            });
        }
    }
}F
Not yet supported.
Go
Not yet supported.
Java
Not yet supported.
JavaScript
Install the dependency:
npm install --save @stackspot/cdk-ecsImport the construct into your project, for example:
const { Stack } = require('aws-cdk-lib');
const { Vpc } = require('aws-cdk-lib/aws-ec2');
const { Ecs } = require('@stackspot/cdk-ecs');
class MyStack extends Stack {
  constructor(scope, id, props) {
    super(scope, id, props);
    const ecs = new Ecs(this, 'MyCluster', {
      clusterName: 'MyCluster',
      vpc: new Vpc(this, 'MyVpc'),
    });
  }
}
module.exports = { MyStack };Python
Not yet supported.
TypeScript
Install the dependency:
npm install --save @stackspot/cdk-ecsImport the construct into your project, for example:
import { Stack, StackProps } from 'aws-cdk-lib';
import { Vpc } from 'aws-cdk-lib/aws-ec2';
import { Construct } from 'constructs';
import { Ecs } from '@stackspot/cdk-ecs';
class MyStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);
    const ecs = new Ecs(this, 'MyCluster', {
      clusterName: 'MyCluster',
      vpc: new Vpc(this, 'MyVpc'),
    });
  }
}
export default MyStack;Construct Props
| Name | Type | Description | 
|---|---|---|
| clusterName | string | The name for the cluster. | 
| containerInsights? | boolean | If true CloudWatch Container Insights will be enabled for the cluster. Default: false. | 
| vpc | IVpc | The VPC to be used. | 
Another Props
TaskDefinitionCreateProps
| Name | Type | Description | 
|---|---|---|
| containerImage | string | The container image to deploy. | 
| containerName | string | The name of the container within the cluster. | 
| containerPort | number | The container port. | 
| cpu | string | The amount of CPU to use. | 
| hostPort | number | The host port. | 
| memoryMiB | string | The amount of memory in MiB to use. | 
| publicIp | boolean | Represents whether the cluster will have public IP. | 
| subnetType | SubnetType | The type of subnet to use. | 
| vpc | IVpc | The VPC to use. | 
Properties
| Name | Type | Description | 
|---|---|---|
| cluster | Cluster | Cluster that will be created. | 
Methods
| Name | Description | 
|---|---|
| addTaskDefinition(scope, props) | Add a task definition to the AWS ECS cluster. | 
| static addTaskDefinitionFromStackEcs(scope, clusterName, props) | Add a task definition to the AWS ECS cluster from the cluster name. | 
addTaskDefinition(scope, props)
public addTaskDefinition(scope: Construct, props: TaskDefinitionCreateProps): EcsRunTaskParameters
- scope Construct
- props TaskDefinitionCreateProps
Returns
Add a task definition to the AWS ECS cluster.
static addTaskDefinitionFromStackEcs(scope, clusterName, props)
public static addTaskDefinitionFromStackEcs(scope: Construct, clusterName: string, props: TaskDefinitionCreateProps): EcsRunTaskParameters
- scope Contruct
- clusterName string
- props TaskDefinitionCreateProps
Returns
Add a task definition to the AWS ECS cluster from the cluster name.
IAM Least privilege
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:AllocateAddress",
        "ec2:AssociateRouteTable",
        "ec2:AttachInternetGateway",
        "ec2:CreateInternetGateway",
        "ec2:CreateNatGateway",
        "ec2:CreateRoute",
        "ec2:CreateRouteTable",
        "ec2:CreateSubnet",
        "ec2:CreateTags",
        "ec2:CreateVpc",
        "ec2:DeleteInternetGateway",
        "ec2:DeleteNatGateway",
        "ec2:DeleteRoute",
        "ec2:DeleteRouteTable",
        "ec2:DeleteSubnet",
        "ec2:DeleteTags",
        "ec2:DeleteVpc",
        "ec2:DescribeAddresses",
        "ec2:DescribeAvailabilityZones",
        "ec2:DescribeInternetGateways",
        "ec2:DescribeNatGateways",
        "ec2:DescribeRouteTables",
        "ec2:DescribeSubnets",
        "ec2:DescribeVpcs",
        "ec2:DetachInternetGateway",
        "ec2:DisassociateRouteTable",
        "ec2:ModifySubnetAttribute",
        "ec2:ModifyVpcAttribute",
        "ec2:ReleaseAddress",
        "ec2:ReplaceRoute",
        "ecs:CreateCluster",
        "ecs:DeleteCluster",
        "ecs:DescribeClusters",
        "ssm:GetParameters"
      ],
      "Resource": "*"
    }
  ]
}Development
Prerequisites
- EditorConfig (Optional)
- Git
- Node.js 17
Setup
cd ecs-jsii-component
npm install0.1.0
4 years ago