1

我正在尝试NewAg-ApiKey在 aws powershell 中运行 cmdlet。我不确定StageKeys. 有人可以澄清一下吗?

目前写New-AgApiKey为:

New-AGApiKey -CustomerId '11' -Description 'aa' -Enabled $True -GenerateDistinctId $True -Name 'newAPIKey'-StageKeys [{"RestApiId":'yz50sp19a7'},{"StageName":'wh1'}] -Force

并得到以下错误

在 C:\Users\sgoswami\Desktop\Scripts\create1.ps1:2 char:132 + ... $True -Name 'newAPIKey'-StageKeys [{"RestApiId":'yz50sp19a7'},{"Stag ... + ~~~~~~~~~~~~~ 表达式或语句中出现意外的标记 ':'yz50sp19a7''。在 C:\Users\sgoswami\Desktop\Scripts\create1.ps1:2 char:159 + .. . Key'-StageKeys [{"RestApiId":'yz50sp19a7'},{"StageName":'wh1'}] -Forc ... + ~~~~~~ Unexpected token ':'wh1'' in expression or statement . + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : UnexpectedToken

4

1 回答 1

1

尝试创建完全没有 StageKeys 的 ApiKey。它不是必需的参数,并且根据New-AGApiKey 文档,此参数已被弃用以支持使用计划

-StageKey StageKey[]

不推荐用于使用计划 - 指定与 API 密钥关联的阶段。
必需的?虚假
立场?命名
接受管道输入?错误的

此选项在 CLI 和其他 SDK 中同样已弃用。

如果您仍需要使用 StageKey,Amazon.APIGateway.Model.StageKey 类型在此处定义,位于适用于 .NET 的 AWS 开发工具包文档中。您可以如下所述在 powershell 中创建此类型的新实例,其中将具有匹配属性名称和值的 powershell 用作新对象的输入:

$obj = New-Object Amazon.APIGateway.Model.StageKey -Property @{ RestApiId = "myId"; StageName = "myName" }

要验证类型是否正确:

$obj | get-member

   TypeName: Amazon.APIGateway.Model.StageKey

Name        MemberType Definition
----        ---------- ----------
Equals      Method     bool Equals(System.Object obj)
GetHashCode Method     int GetHashCode()
GetType     Method     type GetType()
ToString    Method     string ToString()
RestApiId   Property   string RestApiId {get;set;}
StageName   Property   string StageName {get;set;}
于 2017-12-20T01:11:09.353 回答