从SDK以编程方式向AWS OpsWorks堆栈注册实例

2024-06-26 13:22:17 发布

您现在位置:Python中文网/ 问答频道 /正文

正如标题所说,我想在OpsWorks堆栈中注册新的EC2。问题是,“register”命令只能从CLI(shell脚本)运行,而不能从Lambda函数(Python、Java或JS)运行。有什么办法吗?在


Tags: lambda函数命令脚本register标题cli堆栈
1条回答
网友
1楼 · 发布于 2024-06-26 13:22:17

看看这个:register_instance对于Boto3/OpsWork。注册实例有两个部分,Boto3只能完成第二部分。在

We do not recommend using this action to register instances. The complete registration operation has two primary steps, installing the AWS OpsWorks agent on the instance and registering the instance with the stack. RegisterInstance handles only the second step. You should instead use the AWS CLI register command, which performs the entire registration operation. For more information, see Registering an Instance with an AWS OpsWorks Stack

要在Lambda函数中运行CLI,请确保Lambda Exec角色具有执行OpsWork CLI的权限,并在python Lambda中调用类似以下内容:

import subprocess
subprocess.call(["aws", " region", "us-east-1", "opsworks", "register-instance", " stack-id", "<stack-id>"])

查看OpsWorks CLI了解更多信息。在

相关问题 更多 >