Jason Strimpel
Jason Strimpel

Reputation: 15476

Update AWS Lambda API Key Usage Plans with boto3

I have an API Key associated with a particular usage plan. How do I use boto3 to update the usage plan to another usage plan?

I've tried the following methods:

update_api_key() // add, remove and replace operations do not have usage plan path update_usage_plan() // add, remove and replace operations do not have usage plan path

I thought about remove the key from the plan then re-adding but there are no usage plan paths.

Upvotes: 1

Views: 3267

Answers (2)

luismy
luismy

Reputation: 71

I don't know if this is of any help but I run into a similar problem and I did find this post which did the trick for me!

So in my case I wanted to add a new Rest API Stage into an existing Usage Plan so the python script I used was:

import boto3

apigateway = boto3.client('apigateway')
response = apigateway.update_usage_plan(
                    usagePlanId='YOUR_USAGE_PLAN_ID_HERE', 
                    patchOperations=[
                        {
                           'op': 'add',
                           'path': '/apiStages',
                           'value': 'YOUR_REST_API_ID_HERE:v0'
                        }
                    ]
            )

print(response)

I hope this helps :)

Luismy

Upvotes: 4

RyanG
RyanG

Reputation: 4152

You are looking for create_usage_plan_key

i.e.

response = client.create_usage_plan_key(
    usagePlanId='12345',
    keyId='[API_KEY_ID]',
    keyType='API_KEY'
)

Upvotes: 3

Related Questions