我正在关注这里的教程:
https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/how-to-spot-instances.html
并创建了一个 C# Lambda 函数来测试创建现场实例。有问题的功能是:
public async static Task<SpotInstanceRequest> RequestSpotInstance(
AmazonEC2Client ec2Client,
string amiId,
string securityGroupName,
InstanceType instanceType,
string spotPrice,
int instanceCount)
{
var request = new RequestSpotInstancesRequest();
request.SpotPrice = spotPrice;
request.InstanceCount = instanceCount;
var launchSpecification = new LaunchSpecification();
launchSpecification.ImageId = amiId;
launchSpecification.InstanceType = instanceType;
launchSpecification.SecurityGroups.Add(securityGroupName);
request.LaunchSpecification = launchSpecification;
var result = await ec2Client.RequestSpotInstancesAsync(request);
return result.SpotInstanceRequests[0];
}
然而,函数的执行失败:
START RequestId: c64ea78d-d350-4f24-974c-09f31d16c5fd Version: $LATEST
One or more errors occurred. (Value () for parameter groupId is invalid. The value cannot be empty): AggregateException
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at lambda_method(Closure , Stream , Stream , LambdaContextInternal )
我已验证我正在引用一个有效且存在的安全组。我已经尝试了 securityGroupId 值的 groupId、组名和“名称”,但发生了同样的错误。我在哪里错了?我进行了一些搜索,他们指出此错误可能是由于使用组名称的安全组 ID 引起的,但我已经尝试了安全组的所有可用引用,结果相同。