我正在尝试将现有 EC2 实例导入 Terraform。我已获取 EC2 实例用户数据,并将其添加到我的 TF 配置文件中,例如
user_data = <<EOF
<powershell>
& $env:SystemRoot\System32\control.exe "intl.cpl,,/f:`"UKRegion.xml`""
& tzutil /s "GMT Standard Time"
Set-Culture en-GB
</powershell>
EOF
Run Code Online (Sandbox Code Playgroud)
资源导入正常,但当我运行时,terraform plan我得到 TF 想要销毁并重新创建实例,因为 user_data 中的“更改”“强制新资源”。
user_data: "946f756af0df239b19f86a72653e58dcc04c4b27" => "811599030dc713b18c3e35437a82b35095190a81" (forces new resource)
Run Code Online (Sandbox Code Playgroud)
我尝试将用户数据从 EC2 控制台复制并粘贴到 TF 文件中,但这不起作用。这是可能吗?
我有一个Lambda函数,它是对API的基本Python GET调用.它在本地工作正常,但是当我上传到Lambda(以及请求库)时,它不会从API调用返回JSON响应.我只是希望它将整个JSON对象返回给调用者.我在这里做了一些根本错误的事情 - 我偶然发现了几篇文章说不支持从Lambda Python函数返回JSON.
这是代码:
import requests
import json
url = "http://url/api/projects/"
headers = {
'content-type': "application/json",
'x-octopus-apikey': "redacted",
'cache-control': "no-cache"
}
def lambda_handler(event, context):
response = requests.request("GET", url, headers=headers)
return response
Run Code Online (Sandbox Code Playgroud)
我的包中包含请求库和dist,以及json库(我不认为它需要这个).返回的错误消息是:
{
"stackTrace": [
[
"/usr/lib64/python2.7/json/__init__.py",
251,
"dumps",
"sort_keys=sort_keys, **kw).encode(obj)"
],
[
"/usr/lib64/python2.7/json/encoder.py",
207,
"encode",
"chunks = self.iterencode(o, _one_shot=True)"
],
[
"/usr/lib64/python2.7/json/encoder.py",
270,
"iterencode",
"return _iterencode(o, 0)"
],
[
"/var/runtime/awslambda/bootstrap.py",
41,
"decimal_serializer",
"raise TypeError(repr(o) + \" is not JSON serializable\")"
]
],
"errorType": "TypeError",
"errorMessage": "<Response [200]> …Run Code Online (Sandbox Code Playgroud) amazon-web-services python-2.7 restful-architecture aws-lambda
我正在尝试向ELBV2注册新的EC2实例。我正在尝试使用AWSPowershell模块,但无法正常工作。
$InstanceId = (Invoke-WebRequest 'http://169.254.169.254/latest/meta-data/instance-id').Content
Register-ELB2Target -TargetGroupArn 'arn:etc...' -Target $InstanceID
Run Code Online (Sandbox Code Playgroud)
错误是:
Register-ELB2Target : Cannot bind parameter 'Target'. Cannot convert the "i-redacted" value of type "System.String" to type
"Amazon.ElasticLoadBalancingV2.Model.TargetDescription".
Run Code Online (Sandbox Code Playgroud)
我检查了文档,可以看到它也可以占用一个端口(可选)。曾尝试添加端口,但仍然没有运气。