How to use the @pulumi/aws.ec2 function in @pulumi/aws

To help you get started, we’ve selected a few @pulumi/aws examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulumi / tf2pulumi / gen / nodejs / testdata / test_conditionals / index.ts View on Github external
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const config = new pulumi.Config();
const createSg = config.getBoolean("createSg") || false;
// Accept the AWS region as input.
const awsRegion = config.get("awsRegion") || "us-west-2";

const inUsEast1 = (awsRegion === "us-east-1");
// Optionally create a security group and attach some rules.
let defaultSecurityGroup: aws.ec2.SecurityGroup | undefined;
if (createSg) {
    defaultSecurityGroup = new aws.ec2.SecurityGroup("default", {
        description: "Default security group",
    });
}
// SSH access from anywhere
let ingress: aws.ec2.SecurityGroupRule | undefined;
if (createSg) {
    ingress = new aws.ec2.SecurityGroupRule("ingress", {
        cidrBlocks: ["0.0.0.0/0"],
        fromPort: 22,
        protocol: "tcp",
        securityGroupId: defaultSecurityGroup!.id,
        toPort: 22,
        type: "ingress",
    });
}
// outbound internet access
github pulumi / pulumi-aws / examples / metrics / index.ts View on Github external
Name: "My bucket",
    },
});

const bucketMetric = bucket.metrics.firstByteLatency({ unit: "Seconds" });
const bucketAlarm = bucketMetric.createAlarm("alarm" + alarmIndex++, { threshold: 30 , evaluationPeriods: 2 });

const ubuntu = pulumi.output(aws.getAmi({
    filters: [
        { name: "name", values: ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"] },
        { name: "virtualization-type", values: ["hvm"] },
    ],
    mostRecent: true,
    owners: ["099720109477"], // Canonical
}));
const instance = new aws.ec2.Instance("web", {
    ami: ubuntu.apply(ubuntu => ubuntu.id),
    instanceType: "t2.micro",
    tags: {
        Name: "HelloWorld",
    },
});

const instanceMetric = instance.metrics.cpuUtilization();
const instanceAlarm = instanceMetric.createAlarm("alarm" + alarmIndex++, { threshold: 120, evaluationPeriods: 2 });

const cluster = new aws.ecs.Cluster("foo", {});
const clusterMetric = cluster.metrics.cpuUtilization({ unit: "Percent" });
const clusterAlarm = clusterMetric.createAlarm("alarm" + alarmIndex++, { threshold: 50, evaluationPeriods: 2 });

const userPool = new aws.cognito.UserPool("pool", {});
const userPoolMetric = userPool.metrics.compromisedCredentialsRisk();
github pulumi / examples / aws-ts-full-stack-web-app / securityGroups.ts View on Github external
};
}

// loadBalancerSecurityGroup is the security group for the Load Balancer.
export const loadBalancerSecurityGroup = new aws.ec2.SecurityGroup(
    "loadBalancerSecurityGroup", {
    vpcId: defaultVpc.vpcId,
    ingress: [
        oneTcpPortFromAnywhere(httpPort),
        oneTcpPortFromAnywhere(httpsPort),
    ],
    egress: [ ALL ],  // See TerraformEgressNote
});

// vmSecurityGroup is the security group for various EC2 instances.
export const  vmSecurityGroup = new aws.ec2.SecurityGroup(
    "vmSecurityGroup", { 
    vpcId: defaultVpc.vpcId,
    ingress: [
        oneTcpPortFromAnywhere(sshPort),
        oneTcpPortFromAnywhere(httpPort),
        oneTcpPortFromAnywhere(httpsPort),
    ],
});

// TODO: Add databaseSecurityGroup when RDS is hooked up.
github scottslowe / learning-tools / pulumi / sandbox / roles / js-simple-ec2 / files / index.js View on Github external
// Create a new security group for port 80
let group = new aws.ec2.SecurityGroup("pulumi-secgrp", {
    ingress: [
        { protocol: "tcp", fromPort: 22, toPort: 22, cidrBlocks: ["0.0.0.0/0"] },
        { protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] },
    ],
});

// (optional) create a simple web server using the startup script for the instance
let userData =
`#!/bin/bash
echo "Hello, World!" > index.html
nohup python -m SimpleHTTPServer 80 &`;

let server = new aws.ec2.Instance("pulumi-ubuntu", {
    tags: { "Name": "pulumi-ubuntu" },
    instanceType: size,
    securityGroups: [ group.name ], // reference the group object above
    ami: ami,
    userData: userData,             // start a simple web server
    keyName: keypair
});

exports.publicIp = server.publicIp;
exports.publicHostName = server.publicDns;
github pulumi / pulumi-awsx / nodejs / examples / metrics / index.ts View on Github external
Name: "My bucket",
    },
});

const bucketMetric = awsx.s3.metrics.firstByteLatency({ bucket, unit: "Seconds" });
const bucketAlarm = bucketMetric.createAlarm("alarm" + alarmIndex++, { threshold: 30 , evaluationPeriods: 2 });

const ubuntu = pulumi.output(aws.getAmi({
    filters: [
        { name: "name", values: ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"] },
        { name: "virtualization-type", values: ["hvm"] },
    ],
    mostRecent: true,
    owners: ["099720109477"], // Canonical
}));
const instance = new aws.ec2.Instance("web", {
    ami: ubuntu.apply(ubuntu => ubuntu.id),
    instanceType: "t2.micro",
    tags: {
        Name: "HelloWorld",
    },
});

const instanceMetric = awsx.ec2.metrics.cpuUtilization({ instance });
const instanceAlarm = instanceMetric.createAlarm("alarm" + alarmIndex++, { threshold: 120, evaluationPeriods: 2 });

const cluster = new aws.ecs.Cluster("foo", {});
const clusterMetric = awsx.ecs.metrics.cpuUtilization({ cluster, unit: "Percent" });
const clusterAlarm = clusterMetric.createAlarm("alarm" + alarmIndex++, { threshold: 50, evaluationPeriods: 2 });

const userPool = new aws.cognito.UserPool("pool", {});
const userPoolMetric = awsx.cognito.metrics.compromisedCredentialsRisk({ userPool });
github scottslowe / learning-tools / pulumi / sandbox / roles / js-simple-ec2 / files / index.js View on Github external
"use strict";

const aws = require("@pulumi/aws");

// Specify instance size/type
let size = "t2.micro";    // t2.micro is available in the AWS free tier

// Specify AMI
let ami  = "ami-09b42c38b449cfa59"; // AMI for Ubuntu 16.04 in us-west-2 (Oregon)

// Specify key pair to use
// YOU MUST REPLACE THIS VALUE WITH THE CORRECT NAME FOR YOUR ACCOUNT!
let keypair = "aws_rsa";

// Create a new security group for port 80
let group = new aws.ec2.SecurityGroup("pulumi-secgrp", {
    ingress: [
        { protocol: "tcp", fromPort: 22, toPort: 22, cidrBlocks: ["0.0.0.0/0"] },
        { protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] },
    ],
});

// (optional) create a simple web server using the startup script for the instance
let userData =
`#!/bin/bash
echo "Hello, World!" > index.html
nohup python -m SimpleHTTPServer 80 &`;

let server = new aws.ec2.Instance("pulumi-ubuntu", {
    tags: { "Name": "pulumi-ubuntu" },
    instanceType: size,
    securityGroups: [ group.name ], // reference the group object above
github pulumi / pulumi-aws / examples / delete_before_create / mount_target / step1 / index.ts View on Github external
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import { getLinuxAMI } from "./linuxAmi";

const vpc = new aws.ec2.Vpc("vpc", {
    cidrBlock: "10.0.0.0/16",
});

const subnet = new aws.ec2.Subnet("subnet", {
    cidrBlock: "10.0.1.0/24",
    vpcId: vpc.id,
});

const fs = new aws.efs.FileSystem("fs");
const mountTarget = new aws.efs.MountTarget("mt", {
    fileSystemId: fs.id,
    subnetId: subnet.id,
});

const size = aws.ec2.InstanceTypes.T2_Micro;
const instance = new aws.ec2.Instance("dummy-instance", {
github pulumi / pulumi-aws / examples / webserver / variants / zones / index.ts View on Github external
(async () => {
    let zones: string[] = (await aws.getAvailabilityZones()).names.
        filter(x => !x.endsWith("d"));
    for (let i = 0; i < zones.length; i++) {
        let server = new aws.ec2.Instance("web-server-www-" + i, {
            availabilityZone: zones[i],
            instanceType: size,
            securityGroups: [ group.name ],
            ami: getLinuxAMI(size),
        });
    }
})();
github pulumi / examples / policy-packs / aws / index.ts View on Github external
import * as aws from "@pulumi/aws";
import { PolicyPack, ReportViolation, validateTypedResource } from "@pulumi/policy";

const policies = new PolicyPack("aws", {
    policies: [
        {
            name: "discouraged-ec2-public-ip-address",
            description: "Associating public IP addresses is discouraged.",
            enforcementLevel: "advisory",
            validateResource: validateTypedResource(aws.ec2.Instance, (instance, args, reportViolation) => {
                if (instance.associatePublicIpAddress) {
                    reportViolation("Consider not setting associatePublicIpAddress to true.");
                }
            }),
        },
        {
            name: "required-name-tag",
            description: "A 'Name' tag is required.",
            enforcementLevel: "mandatory",
            validateResource: [
                validateTypedResource(aws.ec2.Instance, (instance, args, reportViolation) => {
                    requireNameTag(instance.tags, reportViolation);
                }),
                validateTypedResource(aws.ec2.Vpc, (vpc, args, reportViolation) => {
                    requireNameTag(vpc.tags, reportViolation);
                }),
github pulumi / pulumi-awsx / nodejs / aws-infra / experimental / clusterAutoScaling.ts View on Github external
*
     * If not provided, an 8gb 'gp2' root device will be created.  This device will be deleted upon
     * termination.
     */
    rootBlockDevice?: aws.ec2.LaunchConfigurationArgs["rootBlockDevice"];

    /**
     * Additional EBS block devices to attach to the instance.  See Block Devices below for details.
     *
     * If not provided, a 5gb 'gp2' device will be mounted at '/dev/xvdb' and a 50gb 'gp2' device
     * will be mounted at '/dev/xvdcz'.  Both devices will be deleted upon termination.
     */
    ebsBlockDevices?: aws.ec2.LaunchConfigurationArgs["ebsBlockDevices"];
}>;

export class ClusterAutoScalingLaunchConfiguration extends aws.ec2.LaunchConfiguration {
    public readonly cluster: mod.Cluster;
    /**
     * Optional file system to mount.  Use [cluster.createFileSystem] to create an instance of this.
     */
    public readonly fileSystem?: mod.ClusterFileSystem;

    public readonly instanceProfile: aws.iam.InstanceProfile;

    /**
     * Name to give the auto-scaling-group's cloudformation stack name.
     */
    public readonly stackName: pulumi.Output;

    constructor(name: string, cluster: mod.Cluster,
                args: ClusterAutoScalingLaunchConfigurationArgs = {},
                opts?: pulumi.CustomResourceOptions) {