-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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: add a http proxy with api gateway typescript example #297
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
aea3ca8
feat: add a http proxy with api gateway typescript example
b91a1f9
fix: fix dependencies version
62872ee
docs: Add more information in README.md
f09b850
docs: change naming
d5781f9
docs: Fix naming
8ef1309
docs: Fix broken github url
dd42fc2
Merge branch 'master' into master
cea41f3
Merge branch 'master' into master
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
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,39 @@ | ||
# Proxy-APIGateway | ||
<!--BEGIN STABILITY BANNER--> | ||
--- | ||
|
||
![Stability: Stable](https://img.shields.io/badge/stability-Stable-success.svg?style=for-the-badge) | ||
|
||
> **This is a stable example. It should successfully build out of the box** | ||
> | ||
> This examples does is built on Construct Libraries marked "Stable" and does not have any infrastructure prerequisites to build. | ||
|
||
--- | ||
<!--END STABILITY BANNER--> | ||
|
||
This example creates Http proxy using API gateway of cdk. | ||
If you want to parse another region site(your origin is us-east-1 but scrap site origin is ap-north-east-2) then you can use this proxy. | ||
|
||
> For more information on using Http proxy with apigateway clik [here](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-http.html). | ||
|
||
## Build | ||
|
||
To build this app, you need to be in this example's root folder. Then run the following: | ||
|
||
```bash | ||
npm install -g aws-cdk | ||
npm install | ||
npm run build | ||
``` | ||
|
||
This will install the necessary CDK, then this example's dependencies, and then build your TypeScript files and your CloudFormation template. | ||
|
||
## Deploy | ||
|
||
Run `cdk deploy`. This will deploy / redeploy your Stack to your AWS Account. | ||
|
||
After the deployment you will see the API's URL, which represents the url you can then use. | ||
|
||
## Synthesize Cloudformation Template | ||
|
||
To see the Cloudformation template generated by the CDK, run `cdk synth`, then check the output file in the "cdk.out" directory. |
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,3 @@ | ||
{ | ||
"app": "node index" | ||
} |
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,21 @@ | ||
import * as cdk from "@aws-cdk/core"; | ||
|
||
import { EndpointType } from "@aws-cdk/aws-apigateway"; | ||
|
||
import { Proxy } from "./proxy"; | ||
|
||
export class ProxyStack extends cdk.Stack { | ||
constructor(app: cdk.App, id: string, props?: cdk.StackProps) { | ||
super(app, id, props); | ||
|
||
const proxy = new Proxy(this, "Proxy", { | ||
apiName: "HttpProxy", endpointType: EndpointType.EDGE | ||
}); | ||
|
||
proxy.addProxy("aws", "https://aws.amazon.com/ko"); | ||
} | ||
} | ||
|
||
const app = new cdk.App(); | ||
new ProxyStack(app, "HttpProxy"); | ||
app.synth(); |
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,25 @@ | ||
{ | ||
"name": "proxy-api-gateway", | ||
"version": "1.0.0", | ||
"description": "Generate proxy using api gateway of cdk", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc", | ||
"watch": "tsc -w", | ||
"cdk": "cdk" | ||
}, | ||
"author": { | ||
"name": "Amazon Web Services", | ||
"url": "https://aws.amazon.com", | ||
"organization": true | ||
}, | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@types/node": "^14.0.6", | ||
"typescript": "3.9.3" | ||
}, | ||
"dependencies": { | ||
"@aws-cdk/aws-apigateway": "*", | ||
"@aws-cdk/core": "*" | ||
} | ||
} |
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,47 @@ | ||
import { Construct, CfnOutput } from "@aws-cdk/core"; | ||
|
||
import * as apiGateway from "@aws-cdk/aws-apigateway"; | ||
|
||
export interface ProxyProps { | ||
readonly apiName: string; | ||
readonly endpointType: apiGateway.EndpointType; | ||
} | ||
|
||
export class Proxy extends Construct { | ||
public readonly api: apiGateway.RestApi; | ||
|
||
constructor(scope: Construct, id: string, props: ProxyProps) { | ||
super(scope, id); | ||
|
||
this.api = new apiGateway.RestApi(this, "API", { | ||
restApiName: props.apiName, | ||
endpointConfiguration: { | ||
types: [props.endpointType] | ||
}, | ||
}); | ||
} | ||
|
||
public addProxy(id: string, baseUrl: string, method: string = "GET") { | ||
const namespace = this.api.root.addResource(id); | ||
const proxyResource = new apiGateway.ProxyResource(this, `ProxyResource${method}${id}`, { | ||
parent: namespace, | ||
anyMethod: false, | ||
}); | ||
|
||
proxyResource.addMethod(method, new apiGateway.HttpIntegration(`${baseUrl}/{proxy}`, { | ||
proxy: true, | ||
httpMethod: method, | ||
options: { | ||
requestParameters: { | ||
"integration.request.path.proxy": "method.request.path.proxy" | ||
} | ||
} | ||
}), { | ||
requestParameters: { | ||
"method.request.path.proxy": true | ||
} | ||
}); | ||
|
||
new CfnOutput(this, `EndPoint${method}${id}`, { value: this.api.urlForPath(proxyResource.path) }); | ||
} | ||
} |
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,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"target":"ES2018", | ||
"module": "commonjs", | ||
"lib": ["es2016", "es2017.object", "es2017.string"], | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"noImplicitThis": true, | ||
"alwaysStrict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": false, | ||
"inlineSourceMap": true, | ||
"inlineSources": true, | ||
"experimentalDecorators": true, | ||
"strictPropertyInitialization":false | ||
} | ||
} |
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.
As far as I can tell, this isn't setting up a lambda proxy, but a http proxy
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.
I agree with you, that is my typo