amazon-web-services - 如何从powershell自行终止EC2?

标签 amazon-web-services amazon-ec2 aws-sdk

我需要 powershell 代码来终止实例,而不需要对实例 ID 进行硬编码。

我试过了

aws ec2 terminate-instances --instance-ids 'curl http://169.254.169.254/latest/meta-data/instance-id'

但实例不会终止。有任何想法吗?

最佳答案

正如评论中提到的,我建议使用 AWS Powershell 模块。

以下代码根据 ID 和区域终止实例。

Install-Module AWSPowerShell
Import-Module AWSPowerShell
#Set AWS Credential        
Set-AWSCredential -AccessKey "AccessKey" -SecretKey "SecretKey"     
#Remove EC2 Insatnace
Remove-EC2Instance -InstanceId "InstanceId" -Region "Region"  -Force

如何创建新的AccessKey和SecretKey - Managing Access Keys for Your AWS Account .

AWSPowerShell Module installation.

来自文档:

Terminates a stopped or running Amazon EC2 instance, prompting for confirmation before proceeding.

Note that terminated instances will remain visible after termination (for approximately one hour). The Terminate operation is idempotent; if you terminate an instance more than once, each call will succeed.

AWS Tools for PowerShell - Remove-EC2Instance Documtnetion.

关于amazon-web-services - 如何从powershell自行终止EC2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58432341/

相关文章:

amazon-ec2 - 是否可以使用Whirr在EC2上创建包含Hbase,Hive和Pig的Hadoop集群

dart - Flutter/Dart 和 AWS 开发工具包

node.js - 在 dynamodb Local 中查询全局二级索引

amazon-web-services - Webpack:我应该在生产服务器上构建包还是在本地构建然后上传?

linux - AWS EC2 实例

amazon-web-services - 使用带有 EC2 API 的过滤器检查实例状态

amazon-ec2 - Kubernetes:仅在具有 GPU 的 EC2 节点上运行 Pod

java - 从包含数千个 s3 对象的 s3 存储桶中读取

amazon-web-services - 如何将 AWS SSL 证书添加到 DNN 站点

amazon-web-services - AWS CLI移动文件,路径中带有通配符(星号)