1

I'm trying to run the NewAg-ApiKey cmdlet in aws powershell. I'm unsure on the format of the StageKeys . Can someone clarify this?

Currently writing the New-AgApiKey as:

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

and getting the following errors

At C:\Users\sgoswami\Desktop\Scripts\create1.ps1:2 char:132 + ... $True -Name 'newAPIKey'-StageKeys [{"RestApiId":'yz50sp19a7'},{"Stag ... + ~~~~~~~~~~~~~ Unexpected token ':'yz50sp19a7'' in expression or statement. At 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

Manu
  • 1,685
  • 11
  • 27
the_coder_in_me
  • 143
  • 3
  • 15

1 Answers1

1

Try creating the ApiKey without StageKeys at all. It isn't a required parameter, and per the New-AGApiKey documentation this parameter has been deprecated in favor of usage plans:

-StageKey StageKey[]

DEPRECATED FOR USAGE PLANS - Specifies stages associated with the API key.
Required? False
Position? Named
Accept pipeline input? False

This option has likewise been deprecated in the CLI and other SDKs.

If you still need to use StageKeys, the Amazon.APIGateway.Model.StageKey type is defined here, in the AWS SDK for .NET documentation. You can create a new instance of this type in powershell as described below, where a powershell with matching property names and values is used as input for the new object:

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

To verify the type is correct:

$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;}
Anthony Neace
  • 25,013
  • 7
  • 114
  • 129
  • This works. . However,I am getting a new error for the syntax. any specific reason this could be happening. New-AGApiKey -CustomerId '11' -Description 'aa' -Enabled $True -Gener ... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 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 – the_coder_in_me Dec 20 '17 at 18:17
  • Hello, why exactly are you trying to use deprecated functionality? – Mark Mercurio Dec 21 '17 at 00:12