SCNessen
SCNessen

Reputation: 33

Updateing aws apigateway binaryMediaTypes

I'm attempting to configure and update the binary support options of an AWS API Gateway. I can do this through the web UI without issue, but I would like to script this.

Using the CLI Command Reference pages: http://docs.aws.amazon.com/cli/latest/reference/apigateway/get-rest-api.html http://docs.aws.amazon.com/cli/latest/reference/apigateway/update-rest-api.html

Able to issue a get-rest-api command just fine:

C:\> aws apigateway get-rest-api --rest-api-id [ID]

{
  "id": "[ID]",
    "createdDate": 1490723884,
    "name": "testbinarymediatypes"
}

But when attempting to update the binaryMediaTypes:

PS C:\> aws apigateway update-rest-api --rest-api-id [ID] --patch-operations op=add,path=binaryMediaTypes,value='image/jpg'

An error occurred (BadRequestException) when calling the UpdateRestApi operation: Invalid patch path binaryMediaTypes

Can this be done or am I stuck manually adding the types in the web UI every time?

Upvotes: 3

Views: 2230

Answers (3)

Vitaly Zdanevich
Vitaly Zdanevich

Reputation: 14876

Another automation solution: deploy swagger.

For pulling I use this command:

aws apigateway get-export \
        --rest-api-id xxxxxxxxxx \
        --stage-name prod \
        --export-type swagger \
        --parameters '{"extensions": "integrations,authorizers"}' \
        --accepts application/yaml \
        swagger.yaml

At the end of swagger.yaml I see:

x-amazon-apigateway-binary-media-types:
- "image/png"
- "image/jpeg"

You can upload with this command:

aws apigateway put-rest-api \
        --rest-api-id '5y7lkvtie6' \
        --body 'file://swagger.yaml'

After you will need to deploy your stage through the web console or again with awscli (never tried yet, check aws apigateway help if it is possible).

Upvotes: 0

Stephen Brickner
Stephen Brickner

Reputation: 2602

I am placing this here for anyone looking for a similar solution to updating the apigateway endpointConfiguration.

aws apigateway update-rest-api --rest-api-id yourId --patch-operations "op=replace,path=/endpointConfiguration/types/EDGE,value='REGIONAL'"

Upvotes: 1

Bob Kinney
Bob Kinney

Reputation: 9030

The format for adding these via the CLI is a little non-intuitive.

aws apigateway update-rest-api --rest-api-id [ID] 
          --patch-operations "op=add,path=/binaryMediaTypes/image~1jpg"
aws apigateway update-rest-api --rest-api-id [ID]
          --patch-operations "op=replace,path=/binaryMediaTypes/image~1jpg,value='image/gif'"

Upvotes: 5

Related Questions