Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用CloudFormation模板部署IIS网站_C#_Amazon Cloudformation - Fatal编程技术网

C# 使用CloudFormation模板部署IIS网站

C# 使用CloudFormation模板部署IIS网站,c#,amazon-cloudformation,C#,Amazon Cloudformation,我有一个VisualStudio(C#)部署包(.zip),我已经将它推送到了S3存储中 我想运行我的CloudFormation脚本,让它创建一个IIS服务器的实例(我有这个脚本),然后从S3存储将VisualStudio网站部署到它 我正在寻找一个temple json的例子,它可以做到这一点,我自己还没有尝试过,但是这篇文章,在AWS网站上,也许可以从某个地方开始 我有一个模板,它的功能类似于您要查找的内容。下面是我使用的模板。它可能比你需要的更多,因为它有一个自动缩放组,但它会让你开始。

我有一个VisualStudio(C#)部署包(.zip),我已经将它推送到了S3存储中

我想运行我的CloudFormation脚本,让它创建一个IIS服务器的实例(我有这个脚本),然后从S3存储将VisualStudio网站部署到它


我正在寻找一个temple json的例子,它可以做到这一点,我自己还没有尝试过,但是这篇文章,在AWS网站上,也许可以从某个地方开始

我有一个模板,它的功能类似于您要查找的内容。下面是我使用的模板。它可能比你需要的更多,因为它有一个自动缩放组,但它会让你开始。基本上,您需要IAM用户与云形成交互。UserData中的脚本启动cf init,它完成元数据部分的工作

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Autoscaling for .net Web application.",
    "Parameters": {
        "InstanceType": {
            "Description": "WebServer EC2 instance type",
            "Type": "String",
            "Default": "m1.small",
            "AllowedValues": [
                "t1.micro",
                "m1.small",
                "m1.medium",
                "m1.large",
                "m1.xlarge",
                "m2.xlarge",
                "m2.2xlarge",
                "m2.4xlarge",
                "c1.medium",
                "c1.xlarge",
                "cc1.4xlarge",
                "cc2.8xlarge",
                "cg1.4xlarge"
            ],
            "ConstraintDescription": "Must be a valid EC2 instance type."
        },
        "IamInstanceProfile": {
            "Description": "Name of IAM Profile that will be used by instances to access AWS Services",
            "Type": "String",
            "Default": "YourProfileName"
        },
        "KeyName": {
            "Description": "The EC2 Key Pair to allow access to the instances",
            "Default": "yourkeypair",
            "Type": "String"
        },
        "SpotPriceBid": {
            "Description": "Max bid price of spot instances",
            "Type": "String",
            "Default": ".06"
        },
        "DeployS3Bucket": {
            "Description": "The S3 Bucket where deploy files are stored",
            "Type": "String",
            "Default": "ApplicationBucket"
        },
        "DeployWebS3Key": {
            "Description": "The zip file that holds the website",
            "Type": "String",
            "Default": "Application.zip"
        },
        "DNSHostedZone": {
            "Type": "String",
            "Default": "example.com.",
            "AllowedPattern": "^[\\w\\.]*\\.$",
            "ConstraintDescription": "DNSDomain must end with '.'"
        },
        "DNSSubDomain": {
            "Type": "String",
            "Default": "yoursubdomain"
        }
    },
    "Mappings": {
        "RegionToAMIMap": {
            "us-east-1": {
                "AMI": "ami-1234567"
            }
        }
    },
    "Resources": {
        "IAMUser": {
            "Type": "AWS::IAM::User",
            "Properties": {
                "Path": "/",
                "Policies": [{
                        "PolicyName": "webuser",
                        "PolicyDocument": {
                            "Statement": [{
                                    "Sid": "Stmt1353842250430",
                                    "Action": [
                                        "s3:GetObject"
                                    ],
                                    "Effect": "Allow",
                                    "Resource": [
                                        "arn:aws:s3:::HelgaDogWeb*/*"
                                    ]
                                }, {
                                    "Sid": "Stmt1353842327065",
                                    "Action": [
                                        "cloudformation:DescribeStackResource"
                                    ],
                                    "Effect": "Allow",
                                    "Resource": [
                                        "*"
                                    ]
                                }
                            ]
                        }
                    }
                ]
            }
        },
        "IAMUserAccessKey": {
            "Type": "AWS::IAM::AccessKey",
            "Properties": {
                "UserName": {
                    "Ref": "IAMUser"
                }
            }
        },
        "WebSecurityGroup": {
            "Type": "AWS::EC2::SecurityGroup",
            "Properties": {
                "GroupDescription": "Enable Access From Elastic Load Balancer.",
                "SecurityGroupIngress": [{
                        "IpProtocol": "tcp",
                        "FromPort": "443",
                        "ToPort": "443",
                        "SourceSecurityGroupOwnerId": {
                            "Fn::GetAtt": [
                                "WebLoadBalancer",
                                "SourceSecurityGroup.OwnerAlias"
                            ]
                        },
                        "SourceSecurityGroupName": {
                            "Fn::GetAtt": [
                                "WebLoadBalancer",
                                "SourceSecurityGroup.GroupName"
                            ]
                        }
                    }, {
                        "IpProtocol": "tcp",
                        "FromPort": "80",
                        "ToPort": "80",
                        "SourceSecurityGroupOwnerId": {
                            "Fn::GetAtt": [
                                "WebLoadBalancer",
                                "SourceSecurityGroup.OwnerAlias"
                            ]
                        },
                        "SourceSecurityGroupName": {
                            "Fn::GetAtt": [
                                "WebLoadBalancer",
                                "SourceSecurityGroup.GroupName"
                            ]
                        }
                    }
                ]
            }
        },
        "WebLoadBalancer": {
            "Type": "AWS::ElasticLoadBalancing::LoadBalancer",
            "Properties": {
                "Listeners": [{
                        "InstancePort": "443",
                        "InstanceProtocol": "HTTPS",
                        "LoadBalancerPort": "443",
                        "Protocol": "HTTPS",
                        "SSLCertificateId": "arn:aws:iam::123456789101:server-certificate/example"
                    }
                ],
                "AvailabilityZones": {
                    "Fn::GetAZs": ""
                },
                "HealthCheck": {
                    "HealthyThreshold": "3",
                    "Interval": "30",
                    "Target": "HTTP:80/healthcheck.aspx",
                    "Timeout": 8,
                    "UnhealthyThreshold": "2"
                }
            }
        },
        "WebAsSpotLaunchConfiguration": {
            "Type": "AWS::AutoScaling::LaunchConfiguration",
            "Metadata": {
                "AWS::CloudFormation::Init": {
                    "config": {
                        "sources": {
                            "C:\\inetpub\\wwwroot": {
                                "Fn::Join": [
                                    "/",
                                    [
                                        "http://s3.amazonaws.com", {
                                            "Ref": "DeployS3Bucket"
                                        }, {
                                            "Ref": "DeployWebS3Key"
                                        }
                                    ]
                                ]
                            }
                        },
                        "commands": {
                            "1-set-appPool-identity": {
                                "command": "C:\\Windows\\System32\\inetsrv\\appcmd set config /section:applicationPools /[name='DefaultAppPool'].processModel.identityType:LocalSystem",
                                "waitAfterCompletion": "0"
                            },
                            "2-add-http-binding": {
                                "command": "C:\\Windows\\System32\\inetsrv\\appcmd set site /site.name:\"Default Web Site\" /+bindings.[protocol='http',bindingInformation='*:80:']",
                                "waitAfterCompletion": "0"
                            }
                        }
                    }
                },
                "AWS::CloudFormation::Authentication": {
                    "S3AccessCreds": {
                        "type": "S3",
                        "accessKeyId": {
                            "Ref": "IAMUserAccessKey"
                        },
                        "secretKey": {
                            "Fn::GetAtt": [
                                "IAMUserAccessKey",
                                "SecretAccessKey"
                            ]
                        },
                        "buckets": [{
                                "Ref": "DeployS3Bucket"
                            }
                        ]
                    }
                }
            },
            "Properties": {
                "KeyName": {
                    "Ref": "KeyName"
                },
                "ImageId": {
                    "Fn::FindInMap": [
                        "RegionToAMIMap", {
                            "Ref": "AWS::Region"
                        },
                        "AMI"
                    ]
                },
                "IamInstanceProfile": {
                    "Ref": "IamInstanceProfile"
                },
                "SecurityGroups": [{
                        "Ref": "WebSecurityGroup"
                    }
                ],
                "InstanceType": {
                    "Ref": "InstanceType"
                },
                "SpotPrice": {
                    "Ref": "SpotPriceBid"
                },
                "UserData": {
                    "Fn::Base64": {
                        "Fn::Join": [
                            "",
                            [
                                "<script>\n",
                                "\"C:\\Program Files (x86)\\Amazon\\cfn-bootstrap\\cfn-init.exe\" -v -s ", {
                                    "Ref": "AWS::StackName"
                                },
                                " -r WebAsSpotLaunchConfiguration ",
                                " --access-key ", {
                                    "Ref": "IAMUserAccessKey"
                                },
                                " --secret-key ", {
                                    "Fn::GetAtt": [
                                        "IAMUserAccessKey",
                                        "SecretAccessKey"
                                    ]
                                },
                                "\n",
                                "</script>"
                            ]
                        ]
                    }
                }
            }
        },
        "WebAsSpotGroup": {
            "Type": "AWS::AutoScaling::AutoScalingGroup",
            "Properties": {
                "AvailabilityZones": {
                    "Fn::GetAZs": ""
                },
                "HealthCheckGracePeriod": "120",
                "HealthCheckType": "EC2",
                "LaunchConfigurationName": {
                    "Ref": "WebAsSpotLaunchConfiguration"
                },
                "LoadBalancerNames": [{
                        "Ref": "WebLoadBalancer"
                    }
                ],
                "MaxSize": "20",
                "MinSize": "1",
                "DesiredCapacity": "1"
            }
        },
        "WebAsSpotScaleUpPolicy": {
            "Type": "AWS::AutoScaling::ScalingPolicy",
            "Properties": {
                "AdjustmentType": "PercentChangeInCapacity",
                "AutoScalingGroupName": {
                    "Ref": "WebAsSpotGroup"
                },
                "Cooldown": "420",
                "ScalingAdjustment": "200"
            }
        },
        "WebAsSpotScaleDownPolicy": {
            "Type": "AWS::AutoScaling::ScalingPolicy",
            "Properties": {
                "AdjustmentType": "ChangeInCapacity",
                "AutoScalingGroupName": {
                    "Ref": "WebAsSpotGroup"
                },
                "Cooldown": "60",
                "ScalingAdjustment": "-1"
            }
        },
        "WebAsSpotScaleUpAlarm": {
            "Type": "AWS::CloudWatch::Alarm",
            "Properties": {
                "MetricName": "CPUUtilization",
                "Namespace": "AWS/EC2",
                "Statistic": "Average",
                "Period": "60",
                "EvaluationPeriods": "1",
                "Threshold": "75",
                "AlarmActions": [{
                        "Ref": "WebAsSpotScaleUpPolicy"
                    }
                ],
                "Dimensions": [{
                        "Name": "AutoScalingGroupName",
                        "Value": {
                            "Ref": "WebAsSpotGroup"
                        }
                    }
                ],
                "ComparisonOperator": "GreaterThanThreshold"
            }
        },
        "WebAsSpotScaleDownAlarm": {
            "Type": "AWS::CloudWatch::Alarm",
            "Properties": {
                "MetricName": "CPUUtilization",
                "Namespace": "AWS/EC2",
                "Statistic": "Average",
                "Period": "60",
                "EvaluationPeriods": "2",
                "Threshold": "50",
                "AlarmActions": [{
                        "Ref": "WebAsSpotScaleDownPolicy"
                    }
                ],
                "Dimensions": [{
                        "Name": "AutoScalingGroupName",
                        "Value": {
                            "Ref": "WebAsSpotGroup"
                        }
                    }
                ],
                "ComparisonOperator": "LessThanThreshold"
            }
        },
        "DNSRecord": {
            "Type": "AWS::Route53::RecordSet",
            "Properties": {
                "HostedZoneName": {
                    "Ref": "DNSHostedZone"
                },
                "Comment": "VPN Host. Created by Cloud Formation.",
                "Name": {
                    "Fn::Join": [
                        ".",
                        [{
                                "Ref": "DNSSubDomain"
                            }, {
                                "Ref": "DNSHostedZone"
                            }
                        ]
                    ]
                },
                "Type": "CNAME",
                "TTL": "150",
                "ResourceRecords": [{
                        "Fn::GetAtt": [
                            "WebLoadBalancer",
                            "CanonicalHostedZoneName"
                        ]
                    }
                ]
            },
            "DependsOn": "WebLoadBalancer"
        }
    },
    "Outputs": {}
}
{
“AWSTemplateFormatVersion”:“2010-09-09”,
“说明”:“针对.net Web应用程序的自动缩放。”,
“参数”:{
“InstanceType”:{
“说明”:“Web服务器EC2实例类型”,
“类型”:“字符串”,
“默认值”:“m1.small”,
“允许值”:[
“t1.micro”,
“m1.小型”,
“m1.中等”,
“m1.大型”,
“m1.xlarge”,
“m2.xlarge”,
“m2.2x大”,
“m2.4xL”,
“c1.中等”,
“c1.xlarge”,
“cc1.4XL”,
“cc2.8XL”,
“cg1.4XL”
],
“ConstraintDescription”:“必须是有效的EC2实例类型。”
},
“IAMSInstanceProfile”:{
“描述”:“实例将用于访问AWS服务的IAM配置文件的名称”,
“类型”:“字符串”,
“默认值”:“YourProfileName”
},
“关键字名称”:{
“描述”:“允许访问实例的EC2密钥对”,
“默认值”:“您的密钥对”,
“类型”:“字符串”
},
“SpotPriceBid”:{
“说明”:“现货实例最高出价”,
“类型”:“字符串”,
“默认值”:“.06”
},
“部署存储桶”:{
“说明”:“存储部署文件的S3存储桶”,
“类型”:“字符串”,
“默认值”:“ApplicationBucket”
},
“部署WebS3Key”:{
“描述”:“保存网站的zip文件”,
“类型”:“字符串”,
“默认值”:“Application.zip”
},
“DNSHostedZone”:{
“类型”:“字符串”,
“默认值”:“example.com.”,
“AllowedPattern”:“^[\\w\\.]*\\.$”,
“ConstraintDescription”:“DNSDomain必须以“.”结尾。”
},
“DNSSubDomain”:{
“类型”:“字符串”,
“默认值”:“yoursubdomain”
}
},
“映射”:{
“区域地图”:{
“us-east-1”:{
“AMI”:“AMI-1234567”
}
}
},
“资源”:{
“IAMUser”:{
“类型”:“AWS::IAM::用户”,
“财产”:{
“路径”:“/”,
“政策”:[{
“PolicyName”:“webuser”,
“政策文件”:{
“声明”:[{
“Sid”:“Stmt1353842250430”,
“行动”:[
“s3:GetObject”
],
“效果”:“允许”,
“资源”:[
“arn:aws:s3:::HelgaDogWeb*/*”
]
}, {
“Sid”:“Stmt1353842327065”,
“行动”:[
“cloudformation:DescripteBackResource”
],
“效果”:“允许”,
“资源”:[
"*"
]
}
]
}
}
]
}
},
“IAMUserAccessKey”:{
“类型”:“AWS::IAM::AccessKey”,
“财产”:{
“用户名”:{
“Ref”:“IAMUser”
}
}
},
“Web安全组”:{
“类型”:“AWS::EC2::SecurityGroup”,
“财产”:{
“GroupDescription”:“启用从弹性负载平衡器的访问。”,
“SecurityGroupIngress”:[{
“IpProtocol”:“tcp”,
“FromPort”:“443”,
“托波特”:“443”,
“SourceSecurityGroupOwnerId”:{
“Fn::GetAtt”:[
“WebLoadBalancer”,
“SourceSecurityGroup.OwnerAlias”
]
},
“SourceSecurityGroupName”:{
“Fn::GetAtt”:[
“WebLoadBalancer”,
“SourceSecurityGroup.GroupName”
]
}
}, {
“IpProtocol”:“tcp”,
“FromPort”:“80”,
“托波特”:“80”,
“SourceSecurityGroupOwnerId”:{
“Fn::GetAtt”:[
“WebLoadBalancer”,
“SourceSecurityGroup.OwnerAlias”
]
},
“SourceSecurityGroupName”:{