在我的 cloudformation 模板的命令部分中,aws cli 命令不会将 $SWARM_TOKEN 变量拾取为字符串值。这个想法是将 token 存储在参数存储中以供以后使用。
我在配置集中使用的代码:
AWS::CloudFormation::Init:....
get_and_store_swarm_token:
commands:
get_and_store_token:
command: !Sub
SWARM_TOKEN=$(sudo docker swarm join-token -q worker)
aws ssm put-parameter --name "SwarmToken" --type "SecureString" --value $SWARM_TOKEN --overwrite --region ${AWS::Region}
当我通过 ssh 连接到 EC2 Linux 主机时,我可以执行命令并且它们可以工作。 所以我认为 cfn-init 命令以某种方式启动了一个 session ,其中 $SWARM_TOKEN 变量不被视为字符串。有没有想过如何使 cli 命令工作以便识别 $SWARM_TOKEN 变量?
最佳答案
So i think that the cfn-init command somehow starts a session where the $SWARM_TOKEN variable is not seen as a string.
你是对的。您必须使用 cfn-init
更新 ~/.bashrc
或 /etc/profile
才能导出
SWARM_TOKEN
适用于普通用户。
关于amazon-web-services - 在cloudformation cfn-init中使用linux环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69497392/