# Using an existing API key

**URL:** <https://forum.serverless.com/t/using-an-existing-api-key/770>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [November 14, 2016, 7:25pm UTC](https://forum.serverless.com/t/using-an-existing-api-key/770 "2016-11-14T19:25:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmeuer](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mmeuer/32/290_2.png) [@mmeuer](https://forum.serverless.com/u/mmeuer)\
**Post date:** [November 14, 2016, 7:25pm UTC](https://forum.serverless.com/t/using-an-existing-api-key/770/1 "2016-11-14T19:25:59Z")

</div>

When you specify an API in `severless.yml`, the framework _generates the API key_ and assigns it to the functions. It generates the key even if one with the same name already exists in the environment.

Is there a way to specify an existing API key, rather than have the framework generate it? We really wish to keep generating the key separate from deployments.

Thanks for your time.

-mark

---

<div class="post-metadata">

**Author:** ![manishdalakoti](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@manishdalakoti](https://forum.serverless.com/u/manishdalakoti)\
**Post date:** [April 13, 2017, 8:09pm UTC](https://forum.serverless.com/t/using-an-existing-api-key/770/2 "2017-04-13T20:09:18Z")

</div>

I’m in the same boat. Any ideas?

---

<div class="post-metadata">

**Author:** ![talawahtech](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@talawahtech](https://forum.serverless.com/u/talawahtech)\
**Post date:** [October 1, 2017, 11:51pm UTC](https://forum.serverless.com/t/using-an-existing-api-key/770/3 "2017-10-01T23:51:03Z")

</div>

I was able to do this by manually creating the usage plan for my service using cloudformation syntax in the resources section and referring to my existing key by ID when specifying the UsagePlanKey. They key ID can be found in the AWS console. It is not an ARN, just a random alphanumeric ID.

```
resources:
  Resources:
    MyServiceUsagePlan:
      Type: "AWS::ApiGateway::UsagePlan"
      DependsOn: ApiGatewayRestApi
      Properties:
        UsagePlanName: myservice-dev
        ApiStages:
          - ApiId:
              Ref: ApiGatewayRestApi
            Stage: ${self:provider.stage}
    
    MyServiceUsagePlanKey:
      Type: "AWS::ApiGateway::UsagePlanKey"
      DependsOn: MyServiceUsagePlan
      Properties :
        KeyId: ThisIsWhereYouPutYourExistingKeyID
        KeyType: API_KEY
        UsagePlanId:
          Ref: MyServiceUsagePlan
```

---

<div class="post-metadata">

**Author:** ![niladri\_maiti](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@niladri\_maiti](https://forum.serverless.com/u/niladri_maiti)\
**Post date:** [July 18, 2018, 6:53pm UTC](https://forum.serverless.com/t/using-an-existing-api-key/770/4 "2018-07-18T18:53:26Z")

</div>

Hi,  
I am getting below exception while trying to use existing API Key:  
An error occurred: ApiGatewayApiKey1 - \*\*\*\*\*\*\*\*\* already exists in stack arn:aws:cloudformation:eu-central-1

Thanks

---

<div class="post-metadata">

**Author:** ![petermcg](https://avatars.discourse-cdn.com/v4/letter/p/9e8a1a/32.png) [@petermcg](https://forum.serverless.com/u/petermcg)\
**Post date:** [September 25, 2018, 4:31pm UTC](https://forum.serverless.com/t/using-an-existing-api-key/770/5 "2018-09-25T16:31:11Z")

</div>

This is good but I feel like serverless should supply a more direct way of specifying API keys. My concern with our production APIs is that sometimes, for various reasons, we need to tear down a serverless stack and bring it back up again. Doing so invalidates the keys and this is very bad (need to distribute new keys).
