@gdsgroup/aws-ec2-instance

Provisions a managed ec2 instance with fault tolerance and auto-scale/shutdown operations

Usage no npm install needed!

<script type="module">
  import gdsgroupAwsEc2Instance from 'https://cdn.skypack.dev/@gdsgroup/aws-ec2-instance';
</script>

README

AWS EC2 Instance

Provisions a managed ec2 instance with fault tolerance and auto-scale/shutdown operations

Requirements

Name Version
Pulumi >= 3.8.0, < 4.0.0

Providers

Name Version
aws >= 3.51.0, < 4.0.0

Inputs

Name Description Type Default Required
name Used as the common name for resources and resource URNs created as part of this module string n/a yes
blockDeviceMappings Mappings for additional EBS/block devices other than those provided by the base AMI LaunchTemplateBlockDeviceMapping[] n/a no
description A brief description of the use case for the instance string n/a no
ebsOptimised Whether the instance should be launched with instance storage or EBS storage. Should be 'false' for some instance types like 't2.micro' boolean true no
elasticGraphicsInstanceType Specify and attach elastic graphics to the instance. See: https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/elastic-graphics.html#elastic-graphics-basics LaunchTemplateElasticGpuSpecification[] n/a no
enableTerminationProtection Enable/Disable instance termination protection boolean false no
healthCheckType The Type of health check to apply to the instance healthCheckType EC2 no
instanceProfileArn The ARN of the instance profile to associate with this instance string n/a no
imageId An Id of an AMI you wish to launch. Defaults to the latest good image built from https://github.com/gdsgroup/jugo-image string n/a no
instanceType The instance type you wish to use for this instance string t3.small no
keyPairName The name of the key pair to launch the instance with string pixel no
launchTemplateVersion The Launch Template version/number string $Latest no
maxSize The maximum number of instances in the ASG number 1 no
minSize The minimum number of instances in the ASG number 1 no
privateNetwork Whether or not to launch the instance in a public or private subnet boolean false no
scheduledRecurrence The recurrence of the scheduled action in crontab format. Defaults to 'weekdays at 20:00'. See: https://crontab.guru/examples.html string 0 20 * * 1-5 no
scheduledDesiredSize The desired number of instances the scheduled action should scale the ASG to number 0 no
scheduledMaxSize The maximum number of instances the scheduled action should scale the ASG to number 1 no
scheduledMinSize The minimum number of instances the scheduled action should scale the ASG to number 0 no
shutdownBehaviour The shutdown behaviour for the instance string stop no
tags Tags to apply to the resources [key: string]: string n/a no
userData The user data to provide when launching the instance. No need to encode this data string n/a no
securityGroupIds The Ids of the security groups to assign to the instance(s). Defaults to the 'pixel-streaming' security group string n/a no
vpcId The Id of the vpc to launch the instance in string n/a yes

Module\Component Usage

Basic Usage

import { AwsEc2Instance } from "../ec2";

const newInstance = new AwsEc2Instance("new-instance", {
  name: "new-test-ec2-inst",
  vpcId: "vpc-057cc083d87c6a710",
  description: "Watch this module spin up a test ec2 instance like zoooom!",
});

// Outputs
export const launchTemplateArn = newInstance.launchTemplateArn;
export const autoscalingGrpArn = newInstance.autoscalingGrpArn;

With UserData

import { AwsEc2Instance } from "../ec2";

const newInstance = new AwsEc2Instance("new-instance", {
  name: "new-test-ec2-inst",
  vpcId: "vpc-057cc083d87c6a710",
  description: "Watch this module spin up a test ec2 instance like zoooom!",
  userData: `
<powershell>
# https://www.packer.io/docs/builders/amazon/ebs

write-output "Running User Data Script"
write-host "(host) Running User Data Script"

Set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force -ErrorAction Ignore
</powershell>`,
});

// Outputs
export const launchTemplateArn = newInstance.launchTemplateArn;
export const autoscalingGrpArn = newInstance.autoscalingGrpArn;

Advanced Example

import { AwsEc2Instance } from "../ec2";

const newInstance = new AwsEc2Instance("new-instance", {
  name: "new-test-ec2-inst",
  vpcId: "vpc-057cc083d87c6a710",
  description: "Watch this module spin up a test ec2 instance like zoooom!",
  imageId: "ami-0b161b1eac579e674",
  userData: `
<powershell>
# https://www.packer.io/docs/builders/amazon/ebs

write-output "Running User Data Script"
write-host "(host) Running User Data Script"

Set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force -ErrorAction Ignore
</powershell>`,

  blockDeviceMappings: [
    {
      deviceName: "/dev/sda1",
      ebs: {
        deleteOnTermination: "true",
        encrypted: "true",
        volumeType: "gp2",
        volumeSize: 128, // 128GB
      },
    },
  ],

  elasticGraphicsInstanceType: [
    {
      type: "eg1.large",
    },
  ],

  enableTerminationProtection: true,
  instanceProfileArn:
    "arn:aws:iam::685467893149:instance-profile/ec2InstanceRole",
});

// Outputs
export const launchTemplateArn = newInstance.launchTemplateArn;
export const autoscalingGrpArn = newInstance.autoscalingGrpArn;

Outputs

Name Description
launchTemplateArn The ARN of the launch template
autoscalingGrpArn The ARN of the autoscaling group