【问题标题】:NewAg-ApiKey format errorsNewAg-ApiKey 格式错误
【发布时间】:2018-06-02 11:39:17
【问题描述】:

我正在尝试在 aws powershell 中运行 NewAg-ApiKey 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 ... + ~~~~~~ 表达式或语句中出现意外的标记 ':'wh1''。 + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : UnexpectedToken

【问题讨论】:

    标签: powershell amazon-web-services aws-api-gateway aws-powershell


    【解决方案1】:

    尝试创建完全没有 StageKeys 的 ApiKey。它不是必需的参数,并且根据New-AGApiKey documentation,此参数已被弃用,取而代之的是usage plans

    -StageKey StageKey[]

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

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

    如果您仍需要使用适用于 .NET 的 AWS 开发工具包文档中的 StageKeys,Amazon.APIGateway.Model.StageKey type is defined here。您可以如下所述在 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;}
    

    【讨论】:

    • 这行得通。 .但是,我收到了一个新的语法错误。这可能发生的任何具体原因。 New-AGApiKey -CustomerId '11' -Description 'aa' -Enabled $True -Gene ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [ New-AGApiKey],TypeInitializationException + FullyQualifiedErrorId:System.TypeInitializationException,Amazon.PowerShell.Cmdlets.AG.NewAGApiKeyCmdlet for New-AGApiKey -CustomerId '11' -Description 'aa' -Enabled $True -GenerateDistinctId $True -Name 'newAPIKey'- StageKeys $obj -Force
    • 您好,您究竟为什么要尝试使用已弃用的功能?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 2012-12-13
    • 1970-01-01
    • 2014-08-15
    • 2016-11-18
    相关资源
    最近更新 更多