0.1.0 • Published 2 years ago

@stackspot/cdk-ecs v0.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

container-env-jsii-component

aws-cdk jsii npm-version nuget-version npm-downloads nuget-downloads license

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.Ecs

Import 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-ecs

Import 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-ecs

Import 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

NameTypeDescription
clusterNamestringThe name for the cluster.
containerInsights?booleanIf true CloudWatch Container Insights will be enabled for the cluster. Default: false.
vpcIVpcThe VPC to be used.

Another Props

TaskDefinitionCreateProps

NameTypeDescription
containerImagestringThe container image to deploy.
containerNamestringThe name of the container within the cluster.
containerPortnumberThe container port.
cpustringThe amount of CPU to use.
hostPortnumberThe host port.
memoryMiBstringThe amount of memory in MiB to use.
publicIpbooleanRepresents whether the cluster will have public IP.
subnetTypeSubnetTypeThe type of subnet to use.
vpcIVpcThe VPC to use.

Properties

NameTypeDescription
clusterClusterCluster that will be created.

Methods

NameDescription
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): EcsRunTask

Parameters

Returns

Add a task definition to the AWS ECS cluster.

static addTaskDefinitionFromStackEcs(scope, clusterName, props)

public static addTaskDefinitionFromStackEcs(scope: Construct, clusterName: string, props: TaskDefinitionCreateProps): EcsRunTask

Parameters

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

Setup

cd ecs-jsii-component
npm install