Skip to content

Add support for API Gateway V2 #41

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ plugins:

custom:
apiCloudFront:
httpApi: true
domain: my-custom-domain.com
certificate: arn:aws:acm:us-east-1:000000000000:certificate/00000000-1111-2222-3333-444444444444
waf: 00000000-0000-0000-0000-000000000000
Expand All @@ -62,6 +63,12 @@ custom:

### Notes

* `httpApi` can be *false* (default) or *true*. If you are using ApiGatewayV2 for your lambdas this setting must be applied

```
httpApi: true
```

* `domain` can be list, so if you want to add more domains, instead string you list multiple ones:

```
Expand Down
19 changes: 18 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,28 @@ class ServerlessApiCloudFrontPlugin {

prepareDomain(distributionConfig) {
const domain = this.getConfig('domain', null);
const httpApi = this.getConfig("httpApi", false);

if (domain !== null) {
distributionConfig.Aliases = Array.isArray(domain) ? domain : [ domain ];
} else {
delete distributionConfig.Aliases;
}
distributionConfig.Origins[0].DomainName = {
"Fn::Join": [
"",
[
{
Ref: httpApi && "HttpApi" || "ApiGatewayRestApi"
},
".execute-api.",
{
"Ref": "AWS::Region"
},
".amazonaws.com"
]
]
}
}

preparePriceClass(distributionConfig) {
Expand All @@ -99,7 +115,8 @@ class ServerlessApiCloudFrontPlugin {
}

prepareOrigins(distributionConfig) {
distributionConfig.Origins[0].OriginPath = `/${this.options.stage}`;
const httpApi = this.getConfig("httpApi", false);
distributionConfig.Origins[0].OriginPath = httpApi ? "" : `/${this.options.stage}`;
}

prepareCookies(distributionConfig) {
Expand Down
7 changes: 0 additions & 7 deletions resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ Resources:
DistributionConfig:
Origins:
- Id: ApiGateway
DomainName:
Fn::Join:
- ""
- - Ref: ApiGatewayRestApi
- ".execute-api."
- Ref: AWS::Region
- ".amazonaws.com"
CustomOriginConfig:
HTTPPort: '80'
HTTPSPort: '443'
Expand Down