-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pipes-enrichments): support API Gateway enrichment #31794
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9b7f606
feat: support API Gateway enrichment
mazyu36 517aee9
update
mazyu36 2d9a54a
remove spaces
mazyu36 4fe84f2
Merge branch 'main' into pipes-enrichment-api-gateway
mazyu36 0b2f2d9
update
mazyu36 ba903c0
Update integ.api-gateway.ts
mazyu36 2d7dd36
update index
mazyu36 ea77bcb
Merge branch 'main' into pipes-enrichment-api-gateway
mazyu36 cff9cfb
Merge branch 'main' into pipes-enrichment-api-gateway
mazyu36 39a82c8
update README
mazyu36 8545810
Merge branch 'main' into pipes-enrichment-api-gateway
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
111 changes: 111 additions & 0 deletions
111
packages/@aws-cdk/aws-pipes-enrichments-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,111 @@ | ||
import { EnrichmentParametersConfig, IEnrichment, IPipe, InputTransformation } from '@aws-cdk/aws-pipes-alpha'; | ||
import { IRestApi } from 'aws-cdk-lib/aws-apigateway'; | ||
import { IRole, PolicyStatement } from 'aws-cdk-lib/aws-iam'; | ||
import { CfnPipe } from 'aws-cdk-lib/aws-pipes'; | ||
|
||
/** | ||
* Properties for a ApiGatewayEnrichment | ||
*/ | ||
export interface ApiGatewayEnrichmentProps { | ||
/** | ||
* The input transformation for the enrichment | ||
* @see https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes-input-transformation.html | ||
* @default - None | ||
*/ | ||
readonly inputTransformation?: InputTransformation; | ||
|
||
/** | ||
* 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 that need to be sent as part of request invoking the API Gateway REST API. | ||
* | ||
* @default - none | ||
*/ | ||
readonly headerParameters?: Record<string, string>; | ||
|
||
/** | ||
* The path parameter values used to populate the API Gateway REST API path wildcards ("*"). | ||
* | ||
* @default - none | ||
*/ | ||
readonly pathParameterValues?: string[]; | ||
|
||
/** | ||
* The query string keys/values that need to be sent as part of request invoking the EventBridge API destination. | ||
* | ||
* @default - none | ||
*/ | ||
readonly queryStringParameters?: Record<string, string>; | ||
} | ||
|
||
/** | ||
* An API Gateway enrichment for a pipe | ||
*/ | ||
export class ApiGatewayEnrichment implements IEnrichment { | ||
public readonly enrichmentArn: string; | ||
|
||
private readonly inputTransformation?: InputTransformation; | ||
private readonly headerParameters?: Record<string, string>; | ||
private readonly pathParameterValues?: string[]; | ||
private readonly queryStringParameters?: Record<string, string>; | ||
|
||
constructor(private readonly restApi: IRestApi, props?: ApiGatewayEnrichmentProps) { | ||
this.enrichmentArn = restApi.arnForExecuteApi( | ||
props?.method, | ||
props?.path || '/', | ||
props?.stage || this.restApi.deploymentStage.stageName, | ||
); | ||
this.inputTransformation = props?.inputTransformation; | ||
this.headerParameters = props?.headerParameters; | ||
this.queryStringParameters = props?.queryStringParameters; | ||
this.pathParameterValues = props?.pathParameterValues; | ||
} | ||
|
||
bind(pipe: IPipe): EnrichmentParametersConfig { | ||
|
||
const httpParameters: CfnPipe.PipeEnrichmentHttpParametersProperty | undefined = | ||
this.headerParameters ?? | ||
this.pathParameterValues ?? | ||
this.queryStringParameters | ||
? { | ||
headerParameters: this.headerParameters, | ||
pathParameterValues: this.pathParameterValues, | ||
queryStringParameters: this.queryStringParameters, | ||
} | ||
: undefined; | ||
|
||
return { | ||
enrichmentParameters: { | ||
inputTemplate: this.inputTransformation?.bind(pipe).inputTemplate, | ||
httpParameters, | ||
}, | ||
}; | ||
} | ||
|
||
grantInvoke(pipeRole: IRole): void { | ||
pipeRole.addToPrincipalPolicy(new PolicyStatement({ | ||
resources: [this.enrichmentArn], | ||
actions: ['execute-api:Invoke'], | ||
})); | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './api-destination'; | ||
export * from './api-gateway'; | ||
export * from './lambda'; | ||
export * from './stepfunctions'; |
1 change: 1 addition & 0 deletions
1
packages/@aws-cdk/aws-pipes-enrichments-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
109 changes: 109 additions & 0 deletions
109
packages/@aws-cdk/aws-pipes-enrichments-alpha/test/__snapshots__/api-gateway.test.ts.snap
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,109 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`api-destination should grant pipe role invoke access 1`] = ` | ||
{ | ||
"MyPipeRoleCBC8E9AB": { | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "pipes.amazonaws.com", | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
}, | ||
"Type": "AWS::IAM::Role", | ||
}, | ||
"RestApiCloudWatchRoleE3ED6605": { | ||
"DeletionPolicy": "Retain", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "apigateway.amazonaws.com", | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition", | ||
}, | ||
":iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs", | ||
], | ||
], | ||
}, | ||
], | ||
}, | ||
"Type": "AWS::IAM::Role", | ||
"UpdateReplacePolicy": "Retain", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`api-destination should grant pipe role invoke access 2`] = ` | ||
{ | ||
"MyPipeRoleDefaultPolicy31387C20": { | ||
"Properties": { | ||
"PolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "execute-api:Invoke", | ||
"Effect": "Allow", | ||
"Resource": { | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition", | ||
}, | ||
":execute-api:", | ||
{ | ||
"Ref": "AWS::Region", | ||
}, | ||
":", | ||
{ | ||
"Ref": "AWS::AccountId", | ||
}, | ||
":", | ||
{ | ||
"Ref": "RestApi0C43BF4B", | ||
}, | ||
"/", | ||
{ | ||
"Ref": "RestApiDeploymentStageprod3855DE66", | ||
}, | ||
"/*/", | ||
], | ||
], | ||
}, | ||
}, | ||
], | ||
"Version": "2012-10-17", | ||
}, | ||
"PolicyName": "MyPipeRoleDefaultPolicy31387C20", | ||
"Roles": [ | ||
{ | ||
"Ref": "MyPipeRoleCBC8E9AB", | ||
}, | ||
], | ||
}, | ||
"Type": "AWS::IAM::Policy", | ||
}, | ||
} | ||
`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @mazyu36 - I'm curious if you've considered ApiGatewayV2; whether or not the enrichment should cover that case as well, and if so whether that would be a separate construct or also handled by this design?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sumupitchayan
ApigatewayV2(HTTP API) cannot be used because pipes only supports Apigateway(REST API).
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-aws-services-reference.html
The pipes documentation did not clearly state this.
Also, when I tried in the management console, I was unable to use the HTTP API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Can you maybe then also make this more clear in the README?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I've updated README.