{"library":"serverless-add-api-key","title":"Serverless API Key Management Plugin","description":"The `serverless-add-api-key` plugin extends the Serverless Framework to provide enhanced management of AWS API Gateway API keys and usage plans. Unlike native Serverless functionality, this plugin allows associating multiple services with the same API key and usage plan, facilitating consistent authentication across microservices. It automatically creates API keys and usage plans if they don't exist and supports associating existing keys. The current stable version is 4.2.1, with releases typically following major Serverless Framework updates or when new features for API Gateway integration are required. Key differentiators include its ability to reuse existing keys, support for multiple keys per service, and advanced configuration options for usage plans, including quotas and throttling. It also provides secure handling of API key values through KMS encryption, preventing raw keys from being exposed in repositories.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install serverless-add-api-key"],"cli":null},"imports":["plugins:\n  - serverless-add-api-key","custom:\n  apiKeys:\n    - name: MyServiceKey\n      value: ${ssm:/aws/reference/secretsmanager/my-api-secret~partial}\n      usagePlan:\n        name: MyUsagePlan\n        throttle:\n          rateLimit: 10\n          burstLimit: 20","custom:\n  apiKeys:\n    - name: SecureKey\n      value:\n        encrypted: A-KMS-Encrypted-Value\n        kmsKeyRegion: us-east-1"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"service: my-serverless-api\n\nprovider:\n  name: aws\n  runtime: nodejs18.x\n  stage: dev\n  region: us-east-1\n  usagePlan:\n    name: default-api-usage-plan\n    description: Default plan for my-serverless-api\n    throttle:\n      rateLimit: 10\n      burstLimit: 5\n    quota:\n      limit: 1000\n      period: DAY\n\nplugins:\n  - serverless-add-api-key\n\ncustom:\n  apiKeys:\n    - name: MyServiceGlobalKey-${sls:stage}\n      value: ${env:MY_API_KEY_VALUE, 'default-secure-key-1234567890'}\n      usagePlan:\n        name: CustomUsagePlanForGlobalKey-${sls:stage}\n        description: Usage plan specific to the global key for this stage\n        throttle:\n          rateLimit: 20\n          burstLimit: 10\n        quota:\n          limit: 5000\n          period: MONTH\n    - name: MyEncryptedKey-${sls:stage}\n      value:\n        encrypted: AQICAHinIKhx8yV+y97+qS5naGEBUQrTP8RPE4HDnVvd0AzJ/wGF2tC0dPMHO... # Replace with actual KMS encrypted value\n        kmsKeyRegion: us-east-1 # Specify the region where the KMS key is located\n    - name: AnotherServiceKey-${sls:stage} # This key will use the provider-level usagePlan\n\nfunctions:\n  hello:\n    handler: handler.hello\n    events:\n      - httpApi:\n          path: /hello\n          method: get\n          private: true # Enforce API key usage\n\n# handler.js (example)\n// exports.hello = async (event) => {\n//   return {\n//     statusCode: 200,\n//     body: JSON.stringify({ message: 'Hello from Serverless API Key!' }),\n//   };\n// };","lang":"yaml","description":"This quickstart demonstrates how to configure `serverless-add-api-key` to create multiple API keys, including one with a custom usage plan, one with a KMS-encrypted value, and another that defaults to the provider-level usage plan. It shows how to integrate keys with HTTP API Gateway endpoints and use stage-specific naming.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}