amazon-web-services - 在cloudformation cfn-init中使用linux环境变量

标签 amazon-web-services docker aws-cloudformation docker-swarm

在我的 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/

相关文章:

amazon-web-services - 使用 Cloudformation 将 API 网关与 SNS 集成

amazon-web-services - SNS 主题未发布到 SQS

amazon-web-services - 使用 Docker 时的 EMR Spark 部署模式

amazon-web-services - 云信息 : How to pass a string through cloudformation script into UserData?

aws-lambda - Lambda 支持的自定义资源 cf 模板返回 'CREATE_FAILED'

amazon-web-services - SNS 主题可以成为 EventBridge 的来源吗?

java - AWS Java sdk如何将标签设置为卷

docker - 如何使用 Cloud sql 代理通过 GKE 配置 Cloud SQL?

postgresql - 我在哪里可以找到 postgresql 的精确 pgdg 分布?

bootstrapping - 如果您在 cloudformation 模板中使用 cfn-init,那么烘焙 AMI 是否有意义?