0.1.3 • Published 2 years ago

@gdsgroup/aws-ec2-instance v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

AWS EC2 Instance

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

Requirements

NameVersion
Pulumi>= 3.8.0, < 4.0.0

Providers

NameVersion
aws>= 3.51.0, < 4.0.0

Inputs

NameDescriptionTypeDefaultRequired
nameUsed as the common name for resources and resource URNs created as part of this modulestringn/ayes
blockDeviceMappingsMappings for additional EBS/block devices other than those provided by the base AMILaunchTemplateBlockDeviceMapping[]n/ano
descriptionA brief description of the use case for the instancestringn/ano
ebsOptimisedWhether the instance should be launched with instance storage or EBS storage. Should be 'false' for some instance types like 't2.micro'booleantrueno
elasticGraphicsInstanceTypeSpecify and attach elastic graphics to the instance. See: https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/elastic-graphics.html#elastic-graphics-basicsLaunchTemplateElasticGpuSpecification[]n/ano
enableTerminationProtectionEnable/Disable instance termination protectionbooleanfalseno
healthCheckTypeThe Type of health check to apply to the instancehealthCheckTypeEC2no
instanceProfileArnThe ARN of the instance profile to associate with this instancestringn/ano
imageIdAn Id of an AMI you wish to launch. Defaults to the latest good image built from https://github.com/gdsgroup/jugo-imagestringn/ano
instanceTypeThe instance type you wish to use for this instancestringt3.smallno
keyPairNameThe name of the key pair to launch the instance withstringpixelno
launchTemplateVersionThe Launch Template version/numberstring$Latestno
maxSizeThe maximum number of instances in the ASGnumber1no
minSizeThe minimum number of instances in the ASGnumber1no
privateNetworkWhether or not to launch the instance in a public or private subnetbooleanfalseno
scheduledRecurrenceThe recurrence of the scheduled action in crontab format. Defaults to 'weekdays at 20:00'. See: https://crontab.guru/examples.htmlstring0 20 * * 1-5no
scheduledDesiredSizeThe desired number of instances the scheduled action should scale the ASG tonumber0no
scheduledMaxSizeThe maximum number of instances the scheduled action should scale the ASG tonumber1no
scheduledMinSizeThe minimum number of instances the scheduled action should scale the ASG tonumber0no
shutdownBehaviourThe shutdown behaviour for the instancestringstopno
tagsTags to apply to the resources[key: string]: stringn/ano
userDataThe user data to provide when launching the instance. No need to encode this datastringn/ano
securityGroupIdsThe Ids of the security groups to assign to the instance(s). Defaults to the 'pixel-streaming' security groupstringn/ano
vpcIdThe Id of the vpc to launch the instance instringn/ayes

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

NameDescription
launchTemplateArnThe ARN of the launch template
autoscalingGrpArnThe ARN of the autoscaling group