本文整理汇总了C#中Amazon.EC2.Model.RunInstancesRequest.WithUserData方法的典型用法代码示例。如果您正苦于以下问题:C# RunInstancesRequest.WithUserData方法的具体用法?C# RunInstancesRequest.WithUserData怎么用?C# RunInstancesRequest.WithUserData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.EC2.Model.RunInstancesRequest
的用法示例。
在下文中一共展示了RunInstancesRequest.WithUserData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LaunchInstance
public void LaunchInstance(string instanceName, InstanceSize size, string metadata)
{
var ec2Client = new AmazonEC2Client(_awsCredentials);
string instanceType = "t1.micro";
// WEB: string imageId = "ami-a9da0ec0";
// Compute: string imageId = "ami-443fe32d";
string imageId = "ami-09d96e60";
switch (size)
{
case InstanceSize.Medium:
instanceType = "t1.small";
break;
case InstanceSize.Small:
default:
instanceType = "t1.micro";
break;
}
var request = new RunInstancesRequest()
.WithInstanceType(instanceType)
.WithPlacement(new Placement().WithAvailabilityZone("us-east-1d"))
.WithImageId(imageId)
.WithMinCount(1)
.WithMaxCount(1)
.WithSecurityGroup("default")
.WithKeyName("IgorTest3");
if (!string.IsNullOrEmpty(metadata))
request = request.WithUserData(Convert.ToBase64String(Encoding.UTF8.GetBytes(metadata)));
var runInstancesResponse = ec2Client.RunInstances(request);
var instances = runInstancesResponse.RunInstancesResult.Reservation.RunningInstance;
var index = 0;
foreach (var instance in instances)
{
var name = instanceName;
if (instances.Count > 0)
instanceName = instanceName + index;
var createTagsRequest = new CreateTagsRequest();
createTagsRequest
.WithResourceId(instance.InstanceId)
.WithTag(new Tag().WithKey("Name")
.WithValue(name));
ec2Client.CreateTags(createTagsRequest);
index++;
}
/*
string rsaPrivateKey;
using (var reader = new StreamReader(@"C:\Dev\BlueMetal\CloudAbstractions\SecurityStorage\IgorKeyPair.pem"))
{
rsaPrivateKey = reader.ReadToEnd();
}
var result = ec2Client.GetPasswordData(
new GetPasswordDataRequest().WithInstanceId(instanceId))
.GetPasswordDataResult;
Console.WriteLine(result.GetDecryptedPassword(rsaPrivateKey));
*/
/*
AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client(
appConfig["AWSAccessKey"],
appConfig["AWSSecretKey"],
new AmazonEC2Config().WithServiceURL("https://eu-west-1.ec2.amazonaws.com")
);
DescribeInstancesRequest ec2Request = new DescribeInstancesRequest();
*/
}