UNPKG

aws-cdk-lib

Version:

Version 2 of the AWS Cloud Development Kit library

2 lines (1 loc) 2.12 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StageBase=exports.ApiBase=void 0;var api_mapping_1=()=>{var tmp=require("./api-mapping");return api_mapping_1=()=>tmp,tmp},lib_1=()=>{var tmp=require("../../../aws-apigateway/lib");return lib_1=()=>tmp,tmp},cloudwatch=()=>{var tmp=require("../../../aws-cloudwatch");return cloudwatch=()=>tmp,tmp},core_1=()=>{var tmp=require("../../../core");return core_1=()=>tmp,tmp},errors_1=()=>{var tmp=require("../../../core/lib/errors");return errors_1=()=>tmp,tmp};class ApiBase extends core_1().Resource{metric(metricName,props){return new(cloudwatch()).Metric({namespace:"AWS/ApiGateway",metricName,dimensionsMap:{ApiId:this.apiId},...props}).attachTo(this)}}exports.ApiBase=ApiBase;class StageBase extends core_1().Resource{constructor(){super(...arguments),this.stageVariables={}}_addDomainMapping(domainMapping){if(this._apiMapping)throw new(errors_1()).UnscopedValidationError("Only one ApiMapping allowed per Stage");this._apiMapping=new(api_mapping_1()).ApiMapping(this,`${domainMapping.domainName}${domainMapping.mappingKey}`,{api:this.baseApi,domainName:domainMapping.domainName,stage:this,apiMappingKey:domainMapping.mappingKey}),this.node.addDependency(domainMapping.domainName)}_validateAccessLogSettings(props){if(!props)return;const format=props.format;if(format&&!core_1().Token.isUnresolved(format.toString())&&!/\$context\.(?:requestId|extendedRequestId)\b/.test(format.toString()))throw new(errors_1()).ValidationError("Access log must include either `AccessLogFormat.contextRequestId()` or `AccessLogFormat.contextExtendedRequestId()`",this);return{destinationArn:props.destination.bind(this).destinationArn,format:format?format.toString():lib_1().AccessLogFormat.clf().toString()}}metric(metricName,props){return this.baseApi.metric(metricName,props).with({dimensionsMap:{ApiId:this.baseApi.apiId,Stage:this.stageName}}).attachTo(this)}addStageVariable(name,value){this.stageVariables[name]=value}get _stageVariables(){return Object.keys(this.stageVariables).length>0?{...this.stageVariables}:void 0}}exports.StageBase=StageBase;