최대 4 개의 매개 변수를 사용할 수있는 재사용 가능한 함수를 만들려고합니다 (솔루션은 임의적이어야하지만). AWS CloudFormation에 대한 매개 변수가있는 zip입니다. 따라서 위치 매개 변수를 update_stack으로 전달하지 않으면 CF_ARGS에 포함되지 않습니다.선택적 함수 인수를 처리하십시오.
##
# Update the stack with the given template
# @param: stack_name
# @param: template_body
# @param: [tags]
# @param: [parameters]
##
update_stack() {
# Handle optional func parameters
CF_PARAMS=("--stack-name" "--template-body" "--tags" "--parameters")
# Only include a param if we have a value supplied as an argument. (+1 to ignore script name)
CF_ARGS=($(for i in "${!CF_PARAMS[@]}"; do j=$(($i+1)); if [ -n "${!j}" ]; then echo "${CF_PARAMS[$i]} ${!j}"; fi; done))
# Should make the call as "aws cloudformation create-stack --stack-name $1 --template-body $2"
# If $3 or $4 are not supplied then it should not add them to CFG_ARGS
aws cloudformation create-stack "${CFG_ARGS[@]}"
}
은 내가 이것에 대한 해결책을 찾는 방법에 실패한 난 그냥 방법 apply 떠들썩한 함수 호출에 인수 내 구글 기술을 모르는 건설이 예상대로 작동 CF_ARGS있어 생각 . 도와주세요!
감사합니다, 알렉스
PS.
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
aws: error: argument --stack-name is required
EDIT (1) :
감사 @Barmar 첫 번째 솔루션 나는 awscli에서 점점 한 오류는 (? 어쩌면 큰 따옴표)입니다. 즉,이 오류로 저를 얻었다 :
Unknown options: Description:, Handles, Authentication, &, Access, permissions, Resources:, ##, #, Policies, ##, PolicyDevelopers:, Type:, AWS::IAM::Policy, Properties:, PolicyName:, Developers-cf, #, @todo:, Remove, suffix, PolicyDocument:, Version:, "2012-10-17", Statement:, -, Effect:, Allow, NotAction:, -, iam:*, -, sts:AssumeRole, ...
은 "--template 몸"인수가 따옴표 각 인수에 어쨌든 여러 줄 문자열 (YAML 파일을 정확하게하기)가 무엇입니까? :/
환상적인 : 당신이
IFS
을 설정할 수 있습니다그리고 그것은 하나의 인수로
for
루프에서 출력의 각 행을 처리하게 만 줄 바꿈을 포함! 고마워, 나는 또 다른 문제를 쳤어. 나는 후속 조치, 어떤 제안과 함께 원래의 질문을 업데이 트했습니다? –@AlexLatchford 그 대답을 업데이트했습니다. – Barmar
여러 줄을 너무 나누기 때문에'IFS = $ ";"'를 사용해야했습니다! 아직 완전히 작동하지는 않지만 다음 비트에 대한 새로운 질문이 열릴 것입니다. –