Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
})
this.apiGateway.root.addMethod('DELETE', this.defaultIntegration, {
apiKeyRequired: true,
})
proxy.addMethod('GET', this.defaultIntegration, { apiKeyRequired: true })
proxy.addMethod('POST', this.defaultIntegration, { apiKeyRequired: true })
proxy.addMethod('DELETE', this.defaultIntegration, { apiKeyRequired: true })
this.apiGatewayDomain = getApiGatewayDomain(this.apiGateway.url)
this.apiGatewayOriginPath = getApiGatewayPath(this.apiGateway.url)