
我希望更改启动模板中的某些内容,例如实例类型。这意味着在这样做的同时创建一个新版本。
我已经浏览了 Go 和 Python 的 SDK 文档。似乎都没有让我实现相同目标的参数。
我指的是这些: Go 的函数, Python的函数
请帮帮我...
ec2 启动模板是不可变的。如果需要修改当前启动模板版本,则必须创建新版本。
以下是使用 aws 开发工具包 v2 创建新版本并将其设为默认版本的示例。
安装这两个包:
"github.com/aws/aws-sdk-go-v2/service/ec2" ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
假设您创建了 aws 配置:
func createLaunchTemplateVersion(cfg aws.Config) {
ec2client := ec2.NewFromConfig(cfg)
template := ec2types.RequestLaunchTemplateData{
InstanceType: ec2types.InstanceTypeT2Medium}
createParams := ec2.CreateLaunchTemplateVersionInput{
LaunchTemplateData: &template,
LaunchTemplateName: aws.String("MyTemplate"),
SourceVersion: aws.String("1"),
}
outputCreate, err := ec2client.CreateLaunchTemplateVersion(context.Background(), &createParams)
if err != nil {
log.Fatal(err)
}
if outputCreate.Warning != nil {
log.Fatalf("%v\n", outputCreate.Warning.Errors)
}
// set the new launch type version as the default version
modifyParams := ec2.ModifyLaunchTemplateInput{
DefaultVersion: aws.String(strconv.FormatInt(*outputCreate.LaunchTemplateVersion.VersionNumber, 10)),
LaunchTemplateName: outputCreate.LaunchTemplateVersion.LaunchTemplateName,
}
outputModify, err := ec2client.ModifyLaunchTemplate(context.Background(), &modifyParams)
if err != nil {
log.Fatal(err)
}
fmt.Printf("default version %d\n", *outputModify.LaunchTemplate.DefaultVersionNumber)
}以上就是如何使用 AWS SDK 更改 EC2 启动模板中的实例类型?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号