Skip to content
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(apigatewayv2): http api - endpoint url #11092

Merged
merged 10 commits into from
Oct 30, 2020
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-apigatewayv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-
The code snippet below configures a route `GET /books` with an HTTP proxy integration and uses the `ANY` method to
proxy all other HTTP method calls to `/books` to a lambda proxy.

The URL to the endpoint can be retrieved via the `apiEndpoint` attribute.

```ts
const getBooksIntegration = new HttpProxyIntegration({
url: 'https://get-books-proxy.myproxy.internal',
Expand Down
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-apigatewayv2/lib/http/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ export class HttpApi extends HttpApiBase {

public readonly httpApiId: string;

/**
* The default endpoint for an API
* @attribute
*/
public readonly apiEndpoint: string;

/**
* default stage of the api resource
*/
Expand Down Expand Up @@ -298,6 +304,7 @@ export class HttpApi extends HttpApiBase {

const resource = new CfnApi(this, 'Resource', apiProps);
this.httpApiId = resource.ref;
this.apiEndpoint = resource.attrApiEndpoint;

if (props?.defaultIntegration) {
new HttpRoute(this, 'DefaultRoute', {
Expand Down
3 changes: 1 addition & 2 deletions packages/@aws-cdk/aws-apigatewayv2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@
"props-physical-name-type:@aws-cdk/aws-apigatewayv2.HttpStageProps.stageName",
"props-physical-name:@aws-cdk/aws-apigatewayv2.HttpApiMappingProps",
"props-physical-name:@aws-cdk/aws-apigatewayv2.HttpIntegrationProps",
"props-physical-name:@aws-cdk/aws-apigatewayv2.HttpRouteProps",
"resource-attribute:@aws-cdk/aws-apigatewayv2.HttpApi.apiEndpoint"
"props-physical-name:@aws-cdk/aws-apigatewayv2.HttpRouteProps"
]
},
"stability": "experimental",
Expand Down
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-apigatewayv2/test/http/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,11 @@ describe('HttpApi', () => {
Name: 'Link-2',
});
});

test('apiEndpoint is exported', () => {
const stack = new Stack();
const api = new HttpApi(stack, 'api');

expect(api.apiEndpoint).toBeDefined();
});
});