在命令部分的cloudformation模板中,$SWARM_TOKEN变量没有被aws cli命令作为字符串值拾取。其思想是将令牌存储在参数存储库中以供以后使用。
我在configset中使用的代码:
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命令以某种方式启动一个会话,其中$SWARM_TOKEN变量不被视为字符串。关于如何使cli命令工作以便识别$SWARM_TOKEN变量,有什么想法吗?
所以我认为cfn-init命令以某种方式启动一个会话,其中$SWARM_TOKEN变量不被视为字符串。
你是正确的。对于普通用户,您必须使用cfn-init
将~/.bashrc
或/etc/profile
更新为export
或SWARM_TOKEN
。