# Creating Usage Plan and Api Key Serverless 1.17

**URL:** <https://forum.serverless.com/t/creating-usage-plan-and-api-key-serverless-1-17/2245>\
**Category:** Serverless Framework\
**Created:** [July 8, 2017, 3:29am UTC](https://forum.serverless.com/t/creating-usage-plan-and-api-key-serverless-1-17/2245 "2017-07-08T03:29:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shawnmullen](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@shawnmullen](https://forum.serverless.com/u/shawnmullen)\
**Post date:** [July 8, 2017, 3:29am UTC](https://forum.serverless.com/t/creating-usage-plan-and-api-key-serverless-1-17/2245/1 "2017-07-08T03:29:05Z")

</div>

I am using serverless 1.17. I had a service previously deployed with 1.15, that created an api with a usage plan and an api key.

I removed the stack (sls remove). I checked to make sure ALL resources were gone. I redeployed (sls deploy). I received the following error:

An error occurred while provisioning your stack: EISearchServiceUsagePlanKey - Usage Plan wkw8wr cannot be added because API Key axnaxll39k cannot reference multiple Usage Plans with the same API Stage: atax6mq8o4:dev.

To me this implies that not all the resources were removed when I did an sls remove, even though no resources related to the service existed when I attempted to redeploy. Is there an issue with CloudFormation and UsagePlan? Is sls properly removing the Plan? I assume so since no UsagePlan or Api Key existed when I attempted to redeploy.

Any ideas?

---

<div class="post-metadata">

**Author:** ![shawnmullen](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@shawnmullen](https://forum.serverless.com/u/shawnmullen)\
**Post date:** [July 8, 2017, 5:13am UTC](https://forum.serverless.com/t/creating-usage-plan-and-api-key-serverless-1-17/2245/2 "2017-07-08T05:13:11Z")

</div>

Well, I figured it out.

As I mentioned, originally I was using severless 1.15.1, and I had upgraded to 1.17. While under 1.15, I created and configured usage plans in my serverless file. It appears that in 1.17, usage plans are created automatically if you are adding an api key. So, when I upgraded to 1.17, all of a sudden I am attempting to create another usage plan and adding the same api that was added to the usage plan serverless creates for me.

I must have missed the documentation regarding this change is 1.17. I assume I can configure the usage plan that serverless creates by the normal overriding process. If anyone knows of any gotcha’s let me know.

---

<div class="post-metadata">

**Author:** ![imweijia](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/imweijia/32/1051_2.png) [@imweijia](https://forum.serverless.com/u/imweijia)\
**Post date:** [September 20, 2017, 6:34am UTC](https://forum.serverless.com/t/creating-usage-plan-and-api-key-serverless-1-17/2245/3 "2017-09-20T06:34:46Z")

</div>

Same thing happened for me. I had issues with 1.22.0 whereby a new usage plan was being created for an existing API key. Had to `npm uninstall -g serverless` and reinstall to an older version e.g. `npm install -g serverless@1.10.2` in order to deploy.

---

<div class="post-metadata">

**Author:** ![imweijia](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/imweijia/32/1051_2.png) [@imweijia](https://forum.serverless.com/u/imweijia)\
**Post date:** [September 20, 2017, 6:35am UTC](https://forum.serverless.com/t/creating-usage-plan-and-api-key-serverless-1-17/2245/4 "2017-09-20T06:35:37Z")

</div>

Can you/ how did you configure usage plan IDs manually @shawnmullen?

---

<div class="post-metadata">

**Author:** ![shawnmullen](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@shawnmullen](https://forum.serverless.com/u/shawnmullen)\
**Post date:** [September 20, 2017, 7:38am UTC](https://forum.serverless.com/t/creating-usage-plan-and-api-key-serverless-1-17/2245/5 "2017-09-20T07:38:24Z")

</div>

If you are using the latest version of Serverless and if you already have an api key assigned to a usage plan, you will need to delete the usage plan first and then re-deploy. Serverless will then create a new usage plan and assign the api key to it.

---

<div class="post-metadata">

**Author:** ![shawnmullen](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@shawnmullen](https://forum.serverless.com/u/shawnmullen)\
**Post date:** [September 20, 2017, 7:45am UTC](https://forum.serverless.com/t/creating-usage-plan-and-api-key-serverless-1-17/2245/6 "2017-09-20T07:45:21Z")

</div>

Assuming the following is in the provider section of the serverless.yml file:

apiKeys:  
- UserServiceApiKey

I put the following in the resources section:

resources:  
Resources:  
ApiGatewayRestApi:  
Type: AWS::ApiGateway::RestApi  
Properties:  
Name: my-user-service-api

```
UserServiceUsagePlan:
  Type: AWS::ApiGateway::UsagePlan
  DependsOn: ApiGatewayApiKey1
  Properties:
    Description: Usage plan for the user service api.
    UsagePlanName: user-service-api-usage-plan
    ApiStages:
      - ApiId:
          Ref: ApiGatewayRestApi
        Stage: ${self:provider.stage}

UserServiceUsagePlanKey:
  Type: AWS::ApiGateway::UsagePlanKey
  DependsOn: UserServiceUsagePlan
  Properties :
    KeyId:
      Ref: ApiGatewayApiKey1
    KeyType: API_KEY
    UsagePlanId:
      Ref: UserServiceUsagePlan
```
