-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pipes-targets): add API Gateway (#31954)
- Loading branch information
Showing
17 changed files
with
35,067 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
packages/@aws-cdk/aws-pipes-targets-alpha/lib/api-gateway.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { IInputTransformation, IPipe, ITarget, TargetConfig } from '@aws-cdk/aws-pipes-alpha'; | ||
import { IRestApi } from 'aws-cdk-lib/aws-apigateway'; | ||
import { IRole, PolicyStatement } from 'aws-cdk-lib/aws-iam'; | ||
|
||
/** | ||
* API Gateway REST API target properties. | ||
*/ | ||
export interface ApiGatewayTargetParameters { | ||
/** | ||
* The input transformation to apply to the message before sending it to the target. | ||
* | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-pipes-pipe-pipetargetparameters.html#cfn-pipes-pipe-pipetargetparameters-inputtemplate | ||
* @default - none | ||
*/ | ||
readonly inputTransformation?: IInputTransformation; | ||
|
||
/** | ||
* The method for API Gateway resource. | ||
* | ||
* @default '*' - ANY | ||
*/ | ||
readonly method?: string; | ||
|
||
/** | ||
* The path for the API Gateway resource. | ||
* | ||
* @default '/' | ||
*/ | ||
readonly path?: string; | ||
|
||
/** | ||
* The deployment stage for the API Gateway resource. | ||
* | ||
* @default - the value of `deploymentStage.stageName` of target API Gateway resource. | ||
*/ | ||
readonly stage?: string; | ||
|
||
/** | ||
* The headers to send as part of the request invoking the API Gateway REST API. | ||
* | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-pipes-pipe-pipetargethttpparameters.html#cfn-pipes-pipe-pipetargethttpparameters-headerparameters | ||
* @default - none | ||
*/ | ||
readonly headerParameters?: Record<string, string>; | ||
|
||
/** | ||
* The path parameter values used to populate the API Gateway REST API path wildcards ("*"). | ||
* | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-pipes-pipe-pipetargethttpparameters.html#cfn-pipes-pipe-pipetargethttpparameters-pathparametervalues | ||
* @default - none | ||
*/ | ||
readonly pathParameterValues?: string[]; | ||
|
||
/** | ||
* The query string keys/values that need to be sent as part of request invoking the API Gateway REST API. | ||
* | ||
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-pipes-pipe-pipetargethttpparameters.html#cfn-pipes-pipe-pipetargethttpparameters-querystringparameters | ||
* @default - none | ||
*/ | ||
readonly queryStringParameters?: Record<string, string>; | ||
} | ||
|
||
/** | ||
* An EventBridge Pipes target that sends messages to an EventBridge API destination. | ||
*/ | ||
export class ApiGatewayTarget implements ITarget { | ||
private restApi: IRestApi; | ||
private restApiParameters?: ApiGatewayTargetParameters; | ||
private restApiArn: string; | ||
public readonly targetArn; | ||
|
||
constructor(restApi: IRestApi, parameters?: ApiGatewayTargetParameters) { | ||
this.restApi = restApi; | ||
this.restApiParameters = parameters; | ||
|
||
if (this.restApiParameters?.stage === undefined && this.restApi.deploymentStage === undefined) { | ||
throw Error('The REST API must have a deployed stage.'); | ||
} | ||
|
||
this.restApiArn = this.restApi.arnForExecuteApi( | ||
this.restApiParameters?.method, | ||
this.restApiParameters?.path || '/', | ||
this.restApiParameters?.stage || this.restApi.deploymentStage.stageName, | ||
); | ||
|
||
this.targetArn = this.restApiArn; | ||
} | ||
|
||
grantPush(grantee: IRole): void { | ||
grantee.addToPrincipalPolicy(new PolicyStatement({ | ||
resources: [this.restApiArn], | ||
actions: ['execute-api:Invoke'], | ||
})); | ||
} | ||
|
||
bind(pipe: IPipe): TargetConfig { | ||
if (!this.restApiParameters) { | ||
return { | ||
targetParameters: {}, | ||
}; | ||
} | ||
|
||
return { | ||
targetParameters: { | ||
inputTemplate: this.restApiParameters.inputTransformation?.bind(pipe).inputTemplate, | ||
httpParameters: this.restApiParameters, | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/@aws-cdk/aws-pipes-targets-alpha/rosetta/default.ts-fixture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.