handsome-napkin-75099
04/20/2021, 4:15 PMimport * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
// Step 1: Define the Networking for our service. Will join the appropriate POD network. Pod02 or Pod03.
// Use an existing VPC, subnets, and gateways.
const existingVpc = awsx.ec2.Vpc.fromExistingIds("existingVpc", {
vpcId: "vpc-xxxxxxxxxxxxxx",
publicSubnetIds: ["subnet-1111111111111111", "subnet-22222222222222222", "subnet-3333333333333333"],
//privateSubnetIds: ["subnet-22222222222222222", "subnet-33333333333333333"],
internetGatewayId: "igw-xxxxxxxxxxxxxxxx",
//natGatewayIds: ["nat-00000000000000000", "nat-11111111111111111"],
})
// Step 2: Create an ECS EC2 cluster.
const cluster = new awsx.ecs.Cluster("EBS-to-EFS", {
vpc: existingVpc,
tags: {
"Name": "EBS-to-EFS-cluster",
},
});
export const userData =
`#!/bin/bash`
// Comment out the following lines of the userData script till I get userData to not crash the stack.
// yum install -y amazon-efs-utils
// yum install -y nfs-utils
// yum install -y aws-cfn-bootstrap
// /opt/aws/bin/cfn-init -v --region \${AWS::Region} --stack \${AWS::StackName} --resource ContainerInstances
// /opt/aws/bin/cfn-signal -e \$? --region \${AWS::Region} --stack \${AWS::StackName} --resource ECSAutoScalingGroup
// #open file descriptor for stderr
// exec 2>>/var/log/ecs/ecs-agent-install.log
// set -x
// #verify that the agent is running
// until curl -s <http://localhost:51678/v1/metadata>
// do
// sleep 1
// done
// #install the Docker volume plugin
// docker plugin install rexray/efs REXRAY_PREEMPT=true EFS_REGION=\${AWS::Region} EFS_SECURITYGROUPS=\${EFSSecurityGroup} --grant-all-permissions
// docker plugin install rexray/ebs REXRAY_PREEMPT=true EBS_REGION=\${AWS::Region} --grant-all-permissions
// #restart the ECS agent
// stop ecs
// start ecs`
const asg = cluster.createAutoScalingGroup("asg", {
templateParameters: { minSize: 1 },
subnetIds: existingVpc.publicSubnetIds,
launchConfigurationArgs: {
instanceType: "t2.medium",
associatePublicIpAddress: true,
userData: userData,
},
});
const nginx = new awsx.ecs.EC2Service("nginx", {
cluster,
taskDefinitionArgs: {
containers: {
nginx: {
image: "nginx",
memory: 128,
networkListener: { port: 80},
},
},
},
desiredCount: 2,
});
// Export interesting fields to make them easy to use:
export const vpcId = existingVpc.id;
//export const vpcPrivateSubnetIds = existingVpc.privateSubnetIds;
export const vpcPublicSubnetIds = existingVpc.publicSubnetIds;
If I comment out userData: userData in the Autoscaling Group Definition I have a successful build. When I uncomment the line a include userData in the Autoscaling group the stack errors out with the following.
Diagnostics:
aws:cloudformation:Stack (asg):
error: 1 error occurred:
* creating urn:pulumi:dev::ecs-cpass::awsx:x:ecs:Cluster$awsx:x:autoscaling:AutoScalingGroup$aws:cloudformation/stack:Stack::asg: 1 error occurred:
* error waiting for CloudFormation Stack creation: failed to create CloudFormation stack, rollback requested (ROLLBACK_COMPLETE): ["The following resource(s) failed to create: [Instances]. Rollback requested by user." "Received 0 SUCCESS signal(s) out of 1. Unable to satisfy 100% MinSuccessfulInstancesPercent requirement"]
pulumi:pulumi:Stack (ecs-cpass-dev):
error: update failed
Any hints or code examples that I could follow to get this functioning properly? I have spent way to many hours trying to diagnose how to fix this.witty-candle-66007
04/20/2021, 5:05 PM//
is not a comment in bash. So the bash script being deployed via user-data is failing and causing the instance to essentially fail. Try changing the userdata script to use #
for the commented out line.handsome-napkin-75099
04/20/2021, 6:03 PM#!/bin/bash
. When and If I get that working I will add the following lines into userData.billowy-army-68599
04/20/2021, 6:21 PMhandsome-napkin-75099
04/20/2021, 6:24 PMbillowy-army-68599
04/20/2021, 6:38 PMhandsome-napkin-75099
04/20/2021, 6:39 PMbillowy-army-68599
04/20/2021, 6:41 PMhandsome-napkin-75099
04/20/2021, 6:47 PMbillowy-army-68599
04/20/2021, 6:49 PMhandsome-napkin-75099
04/20/2021, 6:50 PMbillowy-army-68599
04/20/2021, 6:50 PMhandsome-napkin-75099
04/20/2021, 6:53 PMbillowy-army-68599
04/20/2021, 6:59 PM