问题描述
我正在尝试运行aws create lambda函数.如下-
eval $(aws lambda create-function \
--function-name $FUNCTION_NAME \
--runtime $RUNTIME \
--role $ROLE \
--handler $HANDLER \
--region $REGION \
--zip-file $ZIP_FILE \
--profile $PROFILE \
--environment $env_variables)
所有变量都来自命令行. env_variables失败.构造为-
env_variables="Variables={INPUT=${DAYS}}"
DAYS实际上是"20 days"
如何避免此空间并成功传递命令.
最后完成-
env_variables="\"Variables\":{\"INPUT\":\"${DAYS}\"}"
lambda_create_command="aws lambda create-function --function-name $FUNCTION_NAME --runtime $RUNTIME --role $ROLE --handler $HANDLER --region $REGION --zip-file $ZIP_FILE --profile $PROFILE --environment '$env_variables'"
echo "Executing command : $lambda_create_command"
eval $lambda_create_command
重要要点-
-
env_variables
中的行情 - 使用
eval
- 命令字符串即
$env_variables
中的单引号
参考- https://gist.github.com/andywirv/f312d561c9702522f6d4ede1fe2750bd >
完整的工作代码: https://gist.github.com/aniket91/19492b32f570ece202718153661b1823
I am trying to run aws create lambda function. It goes as follows -
eval $(aws lambda create-function \
--function-name $FUNCTION_NAME \
--runtime $RUNTIME \
--role $ROLE \
--handler $HANDLER \
--region $REGION \
--zip-file $ZIP_FILE \
--profile $PROFILE \
--environment $env_variables)
All the variables come from command line. It is failing for env_variables. This gets constructed as -
env_variables="Variables={INPUT=${DAYS}}"
where DAYS is actually "20 days"
How can I avoid this space and pass my command successfully.
Finally following worked -
env_variables="\"Variables\":{\"INPUT\":\"${DAYS}\"}"
lambda_create_command="aws lambda create-function --function-name $FUNCTION_NAME --runtime $RUNTIME --role $ROLE --handler $HANDLER --region $REGION --zip-file $ZIP_FILE --profile $PROFILE --environment '$env_variables'"
echo "Executing command : $lambda_create_command"
eval $lambda_create_command
Important points -
- Quotes in
env_variables
- Use of
eval
- Single quote in command string i.e
$env_variables
Reference - https://gist.github.com/andywirv/f312d561c9702522f6d4ede1fe2750bd
Complete working code :https://gist.github.com/aniket91/19492b32f570ece202718153661b1823
这篇关于由于参数中的空格,Bash脚本因选项未知而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!