in packages/cdk/lib/constructs/api-proxy.ts [51:89]
constructor(scope: Construct, props: ApiProxyProps) {
super(scope, "ApiProxy");
if ((props.lambda && props.loadBalancer) || (!props.lambda && !props.loadBalancer)) {
throw Error("Either lambda or loadBalancer must be specified, but not both");
}
this.accessLogGroup = new LogGroup(this, "AccessLogGroup");
this.restApi = new RestApi(this, "Resource", {
restApiName: props.apiName,
endpointTypes: [EndpointType.REGIONAL],
description: "API proxy endpoint for a service",
apiKeySourceType: ApiKeySourceType.HEADER,
deployOptions: {
loggingLevel: MethodLoggingLevel.INFO,
dataTraceEnabled: true,
accessLogFormat: this.renderAccessLogFormat(),
accessLogDestination: new LogGroupLogDestination(this.accessLogGroup),
},
policy: new PolicyDocument({
statements: [
new PolicyStatement({
actions: ["execute-api:Invoke"],
resources: ["execute-api:/*/*"],
principals: props.allowedAccountIds.map((accountId) => new AccountPrincipal(accountId)),
}),
],
}),
});
const apiTarget = props.lambda ? new LambdaIntegration(props.lambda) : this.renderHttpTarget(props.loadBalancer!);
this.restApi.root.addProxy({
defaultIntegration: apiTarget,
defaultMethodOptions: {
authorizationType: AuthorizationType.IAM,
requestParameters: { "method.request.path.proxy": true },
},
});
}