1

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.

2
  • The doc says: Each op operation can have only one path associated with it Commented Sep 16, 2016 at 3:54
  • I'm only using one path. My point is that none of the paths relate to the usage plan. Commented Sep 16, 2016 at 4:10

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, for the link. It shed light on the format expected by 'value'. In my case it was {'op': 'add', 'path': '/apiStages', 'value': '12l0qhemog:TEST'}
3

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'
)

2 Comments

botocore.exceptions.ClientError: An error occurred (ConflictException) when calling the CreateUsagePlanKey operation: Usage Plan XYZ cannot be added because API Key cannot reference multiple Usage Plans with the same API Stage: ABC:beta
This call does not add new API Keys, it adds new associations between API Keys and Usage Plans. The error message you posted is unrelated. You can also use remove_usage_plan_key to remove the associations between API Keys and Usage Plans.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.