Skip to content

Instantly share code, notes, and snippets.

@masatomix
Last active July 9, 2019 02:34
Show Gist options
  • Save masatomix/236af7a0a156c076677af4ad360a4b7c to your computer and use it in GitHub Desktop.
Save masatomix/236af7a0a156c076677af4ad360a4b7c to your computer and use it in GitHub Desktop.
AWS CloudFormationを使って、セキュリティグループとEC2インスタンスを作成する Infra as code.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"VpcId": {
"Type": "AWS::EC2::VPC::Id",
"Description": "VpcId of your existing Virtual Private Cloud (VPC)"
},
"SubnetId": {
"Type": "AWS::EC2::Subnet::Id",
"Description": "SubnetId of your existing Subnet"
},
"KeyName": {
"Type": "AWS::EC2::KeyPair::KeyName",
"Description": "Keypair of Amazon EC2"
},
"SourceCidr": {
"Description": "IP Cidr from which you are likely to RDP into the instances. You can add rules later by modifying the created security groups e.g. 54.32.98.160/32",
"Type": "String",
"MinLength": "9",
"MaxLength": "18",
"AllowedPattern": "^([0-9]+\\.){3}[0-9]+\\/[0-9]+$",
"Default":"192.168.100.1/32"
}
},
"Resources": {
"sgweb": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "for internal EC2 instances",
"GroupName":"instances",
"VpcId": {
"Ref": "VpcId"
}
}
},
"sgloadbalancerwizard": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "for Load Balancer",
"GroupName":"load-balancer",
"VpcId": {
"Ref": "VpcId"
}
}
},
"ingress1": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"GroupId": {
"Ref": "sgweb"
},
"IpProtocol": "tcp",
"FromPort": "80",
"ToPort": "80",
"SourceSecurityGroupId": {
"Ref": "sgloadbalancerwizard"
}
}
},
"ingress2": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"GroupId": {
"Ref": "sgweb"
},
"IpProtocol": "-1",
"SourceSecurityGroupId": {
"Ref": "sgweb"
}
}
},
"ingress3": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"GroupId": {
"Ref": "sgweb"
},
"IpProtocol": "tcp",
"FromPort": "5601",
"ToPort": "5601",
"SourceSecurityGroupId": {
"Ref": "sgloadbalancerwizard"
}
}
},
"ingress4": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"GroupId": {
"Ref": "sgweb"
},
"IpProtocol": "tcp",
"FromPort": "443",
"ToPort": "443",
"SourceSecurityGroupId": {
"Ref": "sgloadbalancerwizard"
}
}
},
"ingress5": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"GroupId": {
"Ref": "sgweb"
},
"IpProtocol": "tcp",
"FromPort": "3389",
"ToPort": "3389",
"CidrIp": {
"Ref": "SourceCidr"
}
}
},
"ingress6": {
"Type": "AWS::EC2::SecurityGroupIngress",
"Properties": {
"GroupId": {
"Ref": "sgloadbalancerwizard"
},
"IpProtocol": "tcp",
"FromPort": "443",
"ToPort": "443",
"CidrIp": {
"Ref": "SourceCidr"
}
}
},
"egress1": {
"Type": "AWS::EC2::SecurityGroupEgress",
"Properties": {
"GroupId": {
"Ref": "sgweb"
},
"IpProtocol": "-1",
"CidrIp": "0.0.0.0/0"
}
},
"egress2": {
"Type": "AWS::EC2::SecurityGroupEgress",
"Properties": {
"GroupId": {
"Ref": "sgloadbalancerwizard"
},
"IpProtocol": "-1",
"CidrIp": "0.0.0.0/0"
}
},
"instanceorch": {
"Type": "AWS::EC2::Instance",
"Properties": {
"DisableApiTermination": "false",
"InstanceInitiatedShutdownBehavior": "stop",
"ImageId": "ami-077528626d6f3e504",
"InstanceType": "t2.micro",
"KeyName":{
"Ref": "KeyName"
},
"Monitoring": "false",
"Tags": [
{
"Key": "Name",
"Value": "Orchestrator Server"
}
],
"NetworkInterfaces": [
{
"DeleteOnTermination": "true",
"DeviceIndex": 0,
"SubnetId": {
"Ref": "SubnetId"
},
"GroupSet": [
{
"Ref": "sgweb"
}
]
}
]
}
},
"instanceelasticsearch": {
"Type": "AWS::EC2::Instance",
"Properties": {
"DisableApiTermination": "false",
"InstanceInitiatedShutdownBehavior": "stop",
"ImageId": "ami-077528626d6f3e504",
"InstanceType": "t2.micro",
"KeyName":{
"Ref": "KeyName"
},
"Monitoring": "false",
"Tags": [
{
"Key": "Name",
"Value": "Elasticsearch Server"
}
],
"NetworkInterfaces": [
{
"DeleteOnTermination": "true",
"DeviceIndex": 0,
"SubnetId": {
"Ref": "SubnetId"
},
"GroupSet": [
{
"Ref": "sgweb"
}
]
}
]
}
}
},
"Description": "Infra as Code for UiPath Orchestrator/Elasticsearch."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment