0.1.0 • Published 2 years ago

@stackspot/cdk-load-balancer v0.1.0

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

Load Balancer

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

Component to create an Application Load Balancer.

How to use

Below are all languages supported by the AWS CDK.

C

Install the dependency:

dotnet add package StackSpot.Cdk.LoadBalancer
using Amazon.CDK;
using Amazon.CDK.AWS.EC2;
using Constructs;
using StackSpot.Cdk.LoadBalancer;

namespace MyStack
{
    public class MyStack : Stack
    {
        internal MyStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            Vpc vpc = new Vpc(this, "MyVpc");

            LoadBalancer loadBalancer = new LoadBalancer(this, "MyLoadBalancer", new LoadBalancerProps {
                LoadBalancerName = "MyLoabBalancer",
                Subnets = new SubnetSelection {
                    SubnetType = SubnetType.PUBLIC
                },
                Vpc = vpc
            });
        }
    }
}

F

Not yet supported.

Go

Not yet supported.

Java

Not yet supported.

JavaScript

Install the dependency:

npm install --save @stackspot/cdk-load-balancer

Import the construct into your project, for example:

const { Stack } = require('aws-cdk-lib');
const { SubnetType, Vpc } = require('aws-cdk-lib/aws-ec2');
const { LoadBalancer } = require('@stackspot/cdk-load-balancer');

class MyStack extends Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    const vpc = new Vpc(this, 'MyVpc');

    const loadBalancer = new LoadBalancerEnvComponent(this, 'MyALB', {
      loadBalancerName: 'MyLoadBalancer',
      subnets: vpc.selectSubnets({ subnetType: SubnetType.PUBLIC }),
      vpc,
    });
  }
}

module.exports = { MyStack };

Python

Not yet supported.

TypeScript

Install the dependency:

npm install --save @stackspot/cdk-load-balancer

Import the construct into your project, for example:

import { Stack, StackProps } from 'aws-cdk-lib';
import { SubnetType, Vpc } from 'aws-cdk-lib/aws-ec2';
import { Construct } from 'constructs';
import { LoadBalancer } from '@stackspot/cdk-load-balancer';

export class MyStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const vpc = new Vpc(this, 'MyVpc');

    const loadBalancer = new LoadBalancer(this, 'MyLoadBalancer', {
      loadBalancerName: 'MyLoadBalancer',
      subnets: vpc.selectSubnets({ subnetType: SubnetType.PUBLIC }),
      vpc,
    });
  }
}

Construct Props

NameTypeDescription
ingressIpv4Source?string[]Sources that will have access to Load Balancer. Default: [].
internetFacing?booleanWhether this is an internet-facing Load Balancer. Default: false.
loadBalancerNamestringThe name of the Load Balancer.
subnetsSubnetSelectionThe subnets of the Load Balancer.
vpcIVpcThe VPC of the Load Balancer.

Properties

NameTypeDescription
applicationLoadBalancerApplicationLoadBalancerThe Load Balancer to create.
securityGroupSecurityGroupThe security group of the load balancer.

IAM Least privilege

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:AuthorizeSecurityGroupEgress",
        "ec2:CreateSecurityGroup",
        "ec2:DeleteSecurityGroup",
        "ec2:DescribeSecurityGroups",
        "ec2:RevokeSecurityGroupEgress",
        "elasticloadbalancing:CreateLoadBalancer",
        "elasticloadbalancing:Describe*",
        "elasticloadbalancing:ModifyLoadBalancerAttributes",
        "ssm:GetParameters"
      ],
      "Resource": "*"
    }
  ]
}

Development

Prerequisites

Setup

cd load-balancer-jsii-component
npm install