How to use the @aws-cdk/aws-apigateway.CfnApiKey function in @aws-cdk/aws-apigateway

To help you get started, we’ve selected a few @aws-cdk/aws-apigateway examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github seagull-js / seagull / packages / deploy / src / lib / cdk / stack.ts View on Github external
description: 'api key for general api route',
      enabled: true,
      generateDistinctId: true,
      name: `${name}-api-key`,
      stageKeys: [
        { restApiId: new Token(this.apiGateway.restApiId), stageName: 'prod' },
      ],
    }
    const usagePlanConfig = {
      apiStages: [
        { apiId: new Token(this.apiGateway.restApiId), stage: 'prod' },
      ],
      description: 'universal plan to secure the api gateway',
      usagePlanName: 'universal plan',
    }
    const apiKey = new CfnApiKey(this, 'lambdaApiKey', apiKeyConfig)
    const usagePlan = new CfnUsagePlan(this, 'usagePlan', usagePlanConfig)
    const usageKeyConfig = {
      keyId: new Token(apiKey.apiKeyId),
      keyType: 'API_KEY',
      usagePlanId: new Token(usagePlan.usagePlanId),
    }
    // tslint:disable-next-line:no-unused-expression
    new CfnUsagePlanKey(this, 'usageKey', usageKeyConfig)

    const proxy = this.apiGateway.root.addResource('{any+}')
    this.apiGateway.root.addMethod('GET', this.defaultIntegration, {
      apiKeyRequired: true,
    })
    this.apiGateway.root.addMethod('POST', this.defaultIntegration, {
      apiKeyRequired: true,
    })