我怎样才能获得AWS实例标签的用户数据? [英] How can I get AWS Instance Tags in user-data?

查看:593
本文介绍了我怎样才能获得AWS实例标签的用户数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AWS EC2用户数据使用Windows PowerShell脚本。我需要实例引导。我的想法是:

I use aws ec2 userdata with windows powershell scripts. I need instance bootstrapping. My idea is:

  • 在EC2实例标签adds.It的键值名版本,它的价值1.0.0.158-BRANCHNAME

我试图让版本标记值的用户数据。我查了AWS HTTP API。它不能返回标签。我写了简单的PowerShell脚本:

I have tried to get version tag value in userdata. I checked aws http api. It can't return tags. I wrote simple powershell scripts:

$instanceId = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/instance-id")
aws ec2 describe-tags --filters $filter --query 'Tags[*]'

我可以实例ID与AWS HTTP API。我不能获得实例变量,因为AWS EC2用户数据无法启动aws.exe。

I can get instance Id with aws http api. I can't get instance tags because AWS ec2 userdata can't start "aws.exe".

该脚本是正确的 - 实例启动之前,手动运行。

This script is correct - it is manually run before the instance is started.

注:AWS是aws.exe( https://aws.amazon.com/cli /

Note: "aws" is "aws.exe" (https://aws.amazon.com/cli/)

推荐答案

我解决这个问题,我的问题是使用AWS CLI。我使用PowerShell的API,并解决它。

I resolve it, my problem is using aws cli . I use powershell api and fix it.

$instanceId = (New-Object System.Net.WebClient).DownloadString("http://169.254.169.254/latest/meta-data/instance-id")
$versionTag =  Get-EC2Tag | ` Where-Object {$_.ResourceId -eq $instanceId -and $_.Key -eq 'Version'}

这篇关于我怎样才能获得AWS实例标签的用户数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆