英文:
AWS Cli CURL with Header in a Jenkins Pipeline
问题
抱歉,我理解你只需要翻译代码部分,以下是翻译好的部分:
Apologies about this question but I'm running low on ideas about this. We're creating a jenkins pipeline that uses SSM to download a few files to nodes.
The escaping on this seems almost impossible to work out. Even SSM in the command shell is having issues:
header='Authorization: Bearer NjA5MDg4Mdsfsdfsdfsdfdsfsddsfsr1223434'
Then the command:
aws ssm send-command --instance-ids i-12344556677 --document-name AWS-RunShellScript --parameters "commands=cd /tmp; wget -d --header=${header} https://git.org/projects/files/raw/requirements.txt" --output text --query Command.CommandId --region eu-west-1
I've tried multiple \, different " ' in all sorts of places but I just cannot get it to work.
Example error:
aws ssm send-command --instance-ids i-1232131212312 --document-name AWS-RunShellScript --parameters 'commands=cd /tmp; wget -d --header='Authorization: Bearer NjA5M33333444444444444444U' https://git.org/projects/files/raw/requirements.txt' --output text --query Command.CommandId --region eu-west-1
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options: NjA5M33333444444444444444U https://git.org/projects/files/raw/requirements.txt, Bearer
Has anyone here done this?
Thanks,
英文:
Apologies about this question but I'm running low on ideas about this. We're creating a jenkins pipeline that uses SSM to download a few files to nodes.
The escaping on this seems almost impossible to work out. Even SSM in the command shell is having issues:
header='Authorization: Bearer NjA5MDg4Mdsfsdfsdfsdfdsfsddsfsr1223434'
Then the command:
aws ssm send-command --instance-ids i-12344556677 --document-name AWS-RunShellScript --parameters "commands=cd /tmp; wget -d --header=${header} https://git.org/projects/files/raw/requirements.txt" --output text --query Command.CommandId --region eu-west-1
I've tried multiple \, different " ' in all sorts of places but I just cannot get it to work.
Example error:
aws ssm send-command --instance-ids i-1232131212312 --document-name AWS-RunShellScript --parameters 'commands=cd /tmp; wget -d --header='Authorization: Bearer NjA5M33333444444444444444U' https://git.org/projects/files/raw/requirements.txt' --output text --query Command.CommandId --region eu-west-1
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options: NjA5M33333444444444444444U https://git.org/projects/files/raw/requirements.txt, Bearer
Has anyone here done this?
Thanks,
答案1
得分: 1
如果您因为需要进行严格的命令转义而感到困扰,可以考虑创建一个文件,然后使用cat命令进行转储:
aws ssm send-command --document-name "AWS-RunShellScript" \
--instance-ids i-12344556677 \
--parameters "commands=$(cat command.txt)" \
--output text --query Command.CommandId --region eu-west-1
如果您想要快速的转义修复,您也可以尝试:
header='Authorization: Bearer NjA5MDg4Mdsfsdfsdfsdfdsfsddsfsr1223434'
aws ssm send-command --instance-ids i-12344556677 \
--document-name AWS-RunShellScript \
--parameters "commands=['cd /tmp', 'wget -d --header='${header}' https://git.org/projects/files/raw/requirements.txt']" \
--output text \
--query Command.CommandId --region eu-west-1
英文:
If you are struggling with running commands due to hard core escaping requirements, you may want to consider creating a file that you can then dump using cat command:
aws ssm send-command --document-name "AWS-RunShellScript" \
--instance-ids i-12344556677 \
--parameters "commands=$(cat command.txt)" \
--output text --query Command.CommandId --region eu-west-1
If you want a quick escaping fix, you can also try:
header='Authorization: Bearer NjA5MDg4Mdsfsdfsdfsdfdsfsddsfsr1223434'
aws ssm send-command --instance-ids i-12344556677 \
--document-name AWS-RunShellScript \
--parameters "commands=['cd /tmp', 'wget -d --header=\'${header}\' https://git.org/projects/files/raw/requirements.txt']" \
--output text \
--query Command.CommandId --region eu-west-1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论