我正在尝试运行以下命令:
aws cloudformation update-stack --stack-name $stack.Trim('"') --use-previous-template --parameters file://./parameters.json
这是parameters.json的内容(您可以复制并粘贴here来检查它是否为有效的JSON字符串):
[{"ParameterKey":"directoryName","UsePreviousValue":true},{"ParameterKey":"CodeDeployServiceRole","UsePreviousValue":true},{"ParameterKey":"ApplicationType","UsePreviousValue":true},{"ParameterKey":"EnvironmentCode","UsePreviousValue":true},{"ParameterKey":"InstanceRoleInstanceProfile","UsePreviousValue":true},{"ParameterKey":"VPCID","UsePreviousValue":true},{"ParameterKey":"SecurityGroupList","UsePreviousValue":true},{"ParameterKey":"KeyName","UsePreviousValue":true},{"ParameterKey":"Subnets","UsePreviousValue":true},{"ParameterKey":"dnsIpAddresses","UsePreviousValue":true},{"ParameterKey":"directoryId","UsePreviousValue":true},{"ParameterKey":"directoryBIOS","UsePreviousValue":true},{"ParameterKey":"ScalingTermination","UsePreviousValue":true},{"ParameterKey":"EC2ScaleUpCooldown","UsePreviousValue":true},{"ParameterKey":"AttributeDelayTimeout","UsePreviousValue":true},{"ParameterKey":"CwLowOperator","UsePreviousValue":true},{"ParameterKey":"EBSOptimized","UsePreviousValue":true},{"ParameterKey":"PatchingGroupTag","UsePreviousValue":true},{"ParameterKey":"CwHighOperator","UsePreviousValue":true},{"ParameterKey":"SSMInventoryTag","UsePreviousValue":true},{"ParameterKey":"CwHighEvaluations","UsePreviousValue":true},{"ParameterKey":"EC2ScaleUpAdjustment","UsePreviousValue":true},{"ParameterKey":"CwScalingMetric","UsePreviousValue":true},{"ParameterKey":"HealthyThresholdCount","UsePreviousValue":true},{"ParameterKey":"ImageId","ParameterValue":"ami-0b2e03736f1241bbb"},{"ParameterKey":"CodeDeployServiceRole","UsePreviousValue":true},{"ParameterKey":"directoryName","UsePreviousValue":true},{"ParameterKey":"HealthCheckIntervalSeconds","UsePreviousValue":true},{"ParameterKey":"ReleaseId","UsePreviousValue":true},{"ParameterKey":"UnhealthyThresholdCount","UsePreviousValue":true},{"ParameterKey":"EC2ScaleDownAdjustment","UsePreviousValue":true},{"ParameterKey":"ApplicationType","UsePreviousValue":true},{"ParameterKey":"EnvironmentCode","UsePreviousValue":true},{"ParameterKey":"Environment","UsePreviousValue":true},{"ParameterKey":"EbsVolumeType","UsePreviousValue":true},{"ParameterKey":"BackupsEnabled","UsePreviousValue":true},{"ParameterKey":"CwLowPeriod","UsePreviousValue":true},{"ParameterKey":"HealthCheckType","UsePreviousValue":true},{"ParameterKey":"InstanceRoleInstanceProfile","UsePreviousValue":true},{"ParameterKey":"ServiceLevel","UsePreviousValue":true},{"ParameterKey":"TerminatedInstances","UsePreviousValue":true},{"ParameterKey":"VPCID","UsePreviousValue":true},{"ParameterKey":"HealthCheckPath","UsePreviousValue":true},{"ParameterKey":"CwHighPeriod","UsePreviousValue":true},{"ParameterKey":"HealthCheckGracePeriod","UsePreviousValue":true},{"ParameterKey":"HealthCheckTimeoutSeconds","UsePreviousValue":true},{"ParameterKey":"CustomCWConfig","UsePreviousValue":true},{"ParameterKey":"ScalingMin","UsePreviousValue":true},{"ParameterKey":"SecurityGroupList","UsePreviousValue":true},{"ParameterKey":"CwLowEvaluations","UsePreviousValue":true},{"ParameterKey":"directoryBIOS","UsePreviousValue":true},{"ParameterKey":"CustomSSMStepCount","UsePreviousValue":true},{"ParameterKey":"ScalingMax","UsePreviousValue":true},{"ParameterKey":"InstanceType","UsePreviousValue":true},{"ParameterKey":"EncryptEBSVolume","UsePreviousValue":true},{"ParameterKey":"SSMRefreshFrequency","UsePreviousValue":true},{"ParameterKey":"CwHighThreshold","UsePreviousValue":true},{"ParameterKey":"CustomSSMSteps","UsePreviousValue":true},{"ParameterKey":"MinInstancesInService","UsePreviousValue":true},{"ParameterKey":"MatcherCode","UsePreviousValue":true},{"ParameterKey":"EbsVolumeSize","UsePreviousValue":true},{"ParameterKey":"EC2ScaleDownCooldown","UsePreviousValue":true},{"ParameterKey":"Iops","UsePreviousValue":true},{"ParameterKey":"KeyName","UsePreviousValue":true},{"ParameterKey":"Subnets","UsePreviousValue":true},{"ParameterKey":"dnsIpAddresses","UsePreviousValue":true},{"ParameterKey":"CWLogRetention","UsePreviousValue":true},{"ParameterKey":"EnableRackspaceTicket","UsePreviousValue":true},{"ParameterKey":"CwLowThreshold","UsePreviousValue":true},{"ParameterKey":"directoryId","UsePreviousValue":true},{"ParameterKey":"ScalingNotificationTopic","UsePreviousValue":true},{"ParameterKey":"LoadBalancerFullName","UsePreviousValue":true}]
我在运行命令时得到了这个信息:
aws :
At line:1 char:1
+ aws cloudformation update-stack --stack-name $stack.Trim('"') --templ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Error parsing parameter '--parameters': Expected: '=', received: 'ÿ' for input:
ÿþ[ { " P a r a m e t e r K e y " : " d i r e c t o r y N a m e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C o d e D e p l o y S e r v i c e R o l e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r
a m e t e r K e y " : " A p p l i c a t i o n T y p e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E n v i r o n m e n t C o d e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y "
: " I n s t a n c e R o l e I n s t a n c e P r o f i l e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " V P C I D " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S e c u r i t
y G r o u p L i s t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " K e y N a m e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S u b n e t s " , " U s e P r e v i o u s V a
l u e " : t r u e } , { " P a r a m e t e r K e y " : " d n s I p A d d r e s s e s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " d i r e c t o r y I d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r
a m e t e r K e y " : " d i r e c t o r y B I O S " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S c a l i n g T e r m i n a t i o n " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y
" : " E C 2 S c a l e U p C o o l d o w n " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " A t t r i b u t e D e l a y T i m e o u t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " :
" C w L o w O p e r a t o r " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E B S O p t i m i z e d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " P a t c h i n g G r o u p T
a g " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w H i g h O p e r a t o r " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S S M I n v e n t o r y T a g " , " U s e P r e v
i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w H i g h E v a l u a t i o n s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E C 2 S c a l e U p A d j u s t m e n t " , " U s e P r e v i o u
s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w S c a l i n g M e t r i c " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " H e a l t h y T h r e s h o l d C o u n t " , " U s e P r e v i o u s V a l u
e " : t r u e } , { " P a r a m e t e r K e y " : " I m a g e I d " , " P a r a m e t e r V a l u e " : " a m i - 0 b 2 e 0 3 7 3 6 f 1 2 4 1 b b b " } , { " P a r a m e t e r K e y " : " C o d e D e p l o y S e r v i c e R o l e " , " U s e P r e v i o u
s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " d i r e c t o r y N a m e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " H e a l t h C h e c k I n t e r v a l S e c o n d s " , " U s e P r e v i o u s V
a l u e " : t r u e } , { " P a r a m e t e r K e y " : " R e l e a s e I d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " U n h e a l t h y T h r e s h o l d C o u n t " , " U s e P r e v i o u s V a l u e " : t r
u e } , { " P a r a m e t e r K e y " : " E C 2 S c a l e D o w n A d j u s t m e n t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " A p p l i c a t i o n T y p e " , " U s e P r e v i o u s V a l u e " : t r u e } ,
{ " P a r a m e t e r K e y " : " E n v i r o n m e n t C o d e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E n v i
r o n m e n t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E b s V o l u m e T y p e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " B a c k u p s E n a b l e d " , " U s e
P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w L o w P e r i o d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " H e a l t h C h e c k T y p e " , " U s e P r e v i o u s V a l u e " :
t r u e } , { " P a r a m e t e r K e y " : " I n s t a n c e R o l e I n s t a n c e P r o f i l e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S e r v i c e L e v e l " , " U s e P r e v i o u s V a l u e " : t
r u e } , { " P a r a m e t e r K e y " : " T e r m i n a t e d I n s t a n c e s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " V P C I D " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K
e y " : " H e a l t h C h e c k P a t h " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w H i g h P e r i o d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " H e a l t h C h
e c k G r a c e P e r i o d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " H e a l t h C h e c k T i m e o u t S e c o n d s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C u
s t o m C W C o n f i g " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S c a l i n g M i n " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S e c u r i t y G r o u p L i s t "
, " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w L o w E v a l u a t i o n s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " d i r e c t o r y B I O S " , " U s e P r e v i o u
s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C u s t o m S S M S t e p C o u n t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S c a l i n g M a x " , " U s e P r e v i o u s V a l u e " : t r u e
} , { " P a r a m e t e r K e y " : " I n s t a n c e T y p e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E n c r y p t E B S V o l u m e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r
K e y " : " S S M R e f r e s h F r e q u e n c y " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w H i g h T h r e s h o l d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : "
C u s t o m S S M S t e p s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " M i n I n s t a n c e s I n S e r v i c e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " M a t c h e
r C o d e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E b s V o l u m e S i z e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E C 2 S c a l e D o w n C o o l d o w n " ,
" U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " I o p s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " K e y N a m e " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r
a m e t e r K e y " : " S u b n e t s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " d n s I p A d d r e s s e s " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C W L o g R e
t e n t i o n " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " E n a b l e R a c k s p a c e T i c k e t " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " C w L o w
T h r e s h o l d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " d i r e c t o r y I d " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " S c a l i n g N o t i f i c a t i o n T
o p i c " , " U s e P r e v i o u s V a l u e " : t r u e } , { " P a r a m e t e r K e y " : " L o a d B a l a n c e r F u l l N a m e " , " U s e P r e v i o u s V a l u e " : t r u e } ]
^
我已经使用--debug
运行了该命令,并注意到它试图使用速记语法来解析参数:
2019-04-15 14:11:36,069 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.cloudformation.update-stack: calling handler <awscli.argprocess.ParamShorthandParser object at 0x0000020212160F28>
2019-04-15 14:11:36,070 - MainThread - awscli.argprocess - DEBUG - Parsing param --parameters as shorthand
我找不到任何方法可以强制CLI使用JSON语法而不是简写形式来解析参数。从docs看来,它应该自动执行此操作。
有什么想法为什么要尝试使用速记语法?
答案 0 :(得分:0)
问题似乎出在parameters.json的编码上。 我认为由于文件的编码,CLI无法解析parameters.json,因此正试图使用速记语法而不是JSON语法来解析参数。
我使用以下代码创建了文件:
$parameters = "{""ParameterKey"":""directoryName"",""UsePreviousValue"":true},{""ParameterKey"":""CodeDeployServiceRole"",""UsePreviousValue"":true},{""ParameterKey"":""ApplicationType"",""UsePreviousValue"":true},{""ParameterKey"":""EnvironmentCode"",""UsePreviousValue"":true},{""ParameterKey"":""InstanceRoleInstanceProfile"",""UsePreviousValue"":true},{""ParameterKey"":""VPCID"",""UsePreviousValue"":true},{""ParameterKey"":""SecurityGroupList"",""UsePreviousValue"":true},{""ParameterKey"":""KeyName"",""UsePreviousValue"":true},{""ParameterKey"":""Subnets"",""UsePreviousValue"":true},{""ParameterKey"":""dnsIpAddresses"",""UsePreviousValue"":true},{""ParameterKey"":""directoryId"",""UsePreviousValue"":true},{""ParameterKey"":""directoryBIOS"",""UsePreviousValue"":true},"
# generate json file with parameters for stack
foreach ($parameter in $stackJson.Stacks.Parameters){
$parameterKey = $parameter.ParameterKey
if ($parameterKey -eq "ImageId"){
$parameters += "{""ParameterKey"":""$parameterKey"",""ParameterValue"":""$latestAmiId""},"
}
else {
$parameters += "{""ParameterKey"":""$parameterKey"",""UsePreviousValue"":true},"
}
}
$parameters = $parameters.TrimEnd(',')
$parameters = "[" + $parameters + "]"
#$parameters = ConvertFrom-Json $parameters
$parameters | Out-File .\parameters.json
在文件外命令中添加-Encoding ascii
解决了该问题。