Skip to content

Commit

Permalink
Allow extra edge functions (#282)
Browse files Browse the repository at this point in the history
* Allow extra lambda, skipping basic deploys

* Do not trigger main build on PRs
  • Loading branch information
huntharo authored Jan 2, 2023
1 parent 219e80f commit 6a18126
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ jobs:
- microapps-core
- microapps-basic
- microapps-basic-prefix
exclude:
- deployName: ${{ (github.event_name != 'pull_request' || (github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'DEPLOY-BASIC'))) && 'dummy' || 'microapps-basic' }}
- deployName: ${{ (github.event_name != 'pull_request' || (github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'DEPLOY-BASIC-PREFIX'))) && 'dummy' || 'microapps-basic-prefix' }}
name: deploy-${{ matrix.deployName }}
concurrency:
group: deploy-${{ matrix.deployName }}-${{ github.workflow }}-${{ github.event.pull_request.number }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/main-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ on:
branches:
- 'main'
# When testing changes to workflow
pull_request:
branches:
- main
# pull_request:
# branches:
# - main

jobs:
build:
Expand Down
27 changes: 18 additions & 9 deletions packages/microapps-cdk/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,6 @@ CloudFront Distribution to add the Behaviors (Routes) to.

---

##### `apigwyEdgeFunctions`<sup>Optional</sup> <a name="@pwrdrvr/microapps-cdk.AddRoutesOptions.apigwyEdgeFunctions"></a>

- *Type:* [`aws-cdk-lib.aws_cloudfront.EdgeLambda`](#aws-cdk-lib.aws_cloudfront.EdgeLambda)[]

Edge lambdas to associate with the API Gateway routes.

---

##### `createAPIPathRoute`<sup>Optional</sup> <a name="@pwrdrvr/microapps-cdk.AddRoutesOptions.createAPIPathRoute"></a>

- *Type:* `boolean`
Expand Down Expand Up @@ -566,6 +558,14 @@ even if they have a period in the path.

---

##### `edgeLambdas`<sup>Optional</sup> <a name="@pwrdrvr/microapps-cdk.AddRoutesOptions.edgeLambdas"></a>

- *Type:* [`aws-cdk-lib.aws_cloudfront.EdgeLambda`](#aws-cdk-lib.aws_cloudfront.EdgeLambda)[]

Edge lambdas to associate with the API Gateway routes.

---

##### `rootPathPrefix`<sup>Optional</sup> <a name="@pwrdrvr/microapps-cdk.AddRoutesOptions.rootPathPrefix"></a>

- *Type:* `string`
Expand Down Expand Up @@ -860,9 +860,10 @@ API Gateway custom origin domain name.

---

##### `edgeToOriginLambdas`<sup>Optional</sup> <a name="@pwrdrvr/microapps-cdk.MicroAppsCFProps.edgeToOriginLambdas"></a>
##### `edgeLambdas`<sup>Optional</sup> <a name="@pwrdrvr/microapps-cdk.MicroAppsCFProps.edgeLambdas"></a>

- *Type:* [`aws-cdk-lib.aws_cloudfront.EdgeLambda`](#aws-cdk-lib.aws_cloudfront.EdgeLambda)[]
- *Default:* no edge to API Gateway origin functions added

Configuration of the edge to origin lambda functions.

Expand Down Expand Up @@ -1111,6 +1112,14 @@ Optional custom domain name for the API Gateway HTTPv2 API.

---

##### `edgeLambdas`<sup>Optional</sup> <a name="@pwrdrvr/microapps-cdk.MicroAppsProps.edgeLambdas"></a>

- *Type:* [`aws-cdk-lib.aws_cloudfront.EdgeLambda`](#aws-cdk-lib.aws_cloudfront.EdgeLambda)[]

Additional edge lambda functions.

---

##### `originRegion`<sup>Optional</sup> <a name="@pwrdrvr/microapps-cdk.MicroAppsProps.originRegion"></a>

- *Type:* `string`
Expand Down
2 changes: 2 additions & 0 deletions packages/microapps-cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The MicroApps project enables rapidly deploying many web apps to AWS on a single

MicroApps allows many versions of an application to be deployed either as ephemeral deploys (e.g. for pull request builds) or as semi-permanent deploys. The `microapps-router` Lambda function handled routing requests to apps to the current version targeted for a particular application start request using rules as complex as one is interested in implementing (e.g. A/B testing integration, canary releases, per-user rules for logged in users, per-group, per-deparment, and default rules).

2023-01-01 NOTE: The next paragraph is dated as the `iframe` is no longer required for frameworks that write absolute URLs for their static resources and API requests.

Users start applications via a URL such as `[/{prefix}]/{appname}/`, which hits the `microapps-router` that looks up the version of the application to be run, then renders a transparent `iframe` with a link to that version. The URL seen by the user in the browser (and available for bookmarking) has no version in it, so subsequent launches (e.g. the next day or just in another tab) will lookup the version again. All relative URL API requests (e.g. `some/api/path`) will go to the corresponding API version that matches the version of the loaded static files, eliminating issues of incompatibility between static files and API deployments.

For development / testing purposes only, each version of an applicaton can be accessed directly via a URL of the pattern `[/{prefix}]/{appname}/{semver}/`. These "versioned" URLs are not intended to be advertised to end users as they would cause a user to be stuck on a particular version of the app if the URL was bookmarked. Note that the system does not limit access to particular versions of an application, as of 2022-01-26, but that can be added as a feature.
Expand Down
16 changes: 15 additions & 1 deletion packages/microapps-cdk/src/MicroApps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RemovalPolicy } from 'aws-cdk-lib';
import * as acm from 'aws-cdk-lib/aws-certificatemanager';
import * as cf from 'aws-cdk-lib/aws-cloudfront';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as r53 from 'aws-cdk-lib/aws-route53';
import { Construct } from 'constructs';
Expand Down Expand Up @@ -257,6 +258,11 @@ export interface MicroAppsProps {
* This is required when using v2 routing
*/
readonly tableNameForEdgeToOrigin?: string;

/**
* Additional edge lambda functions
*/
readonly edgeLambdas?: cf.EdgeLambda[];
}

/**
Expand Down Expand Up @@ -392,6 +398,8 @@ export class MicroApps extends Construct implements IMicroApps {
requireIAMAuthorization: signingMode !== 'none',
table,
});
const edgeLambdas: cf.EdgeLambda[] = [];

if (signingMode !== 'none' || replaceHostHeader || addXForwardedHostHeader) {
this._edgeToOrigin = new MicroAppsEdgeToOrigin(this, 'edgeToOrigin', {
assetNameRoot,
Expand All @@ -404,6 +412,12 @@ export class MicroApps extends Construct implements IMicroApps {
rootPathPrefix,
tableRulesArn: tableNameForEdgeToOrigin || this._svcs.table.tableName,
});

edgeLambdas.push(...this._edgeToOrigin.edgeToOriginLambdas);
}
// Add any extra lambdas
if (props.edgeLambdas?.length) {
edgeLambdas.push(...props.edgeLambdas);
}
this._cf = new MicroAppsCF(this, 'cft', {
removalPolicy,
Expand All @@ -418,7 +432,7 @@ export class MicroApps extends Construct implements IMicroApps {
bucketLogs: this._s3.bucketLogs,
rootPathPrefix,
createAPIPathRoute,
edgeToOriginLambdas: this._edgeToOrigin ? this._edgeToOrigin.edgeToOriginLambdas : undefined,
...(edgeLambdas.length ? { edgeLambdas } : {}),
});
}
}
14 changes: 7 additions & 7 deletions packages/microapps-cdk/src/MicroAppsCF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ export interface MicroAppsCFProps {
/**
* Configuration of the edge to origin lambda functions
*
* @defaunt - no edge to API Gateway origin functions added
* @default - no edge to API Gateway origin functions added
*/
readonly edgeToOriginLambdas?: cf.EdgeLambda[];
readonly edgeLambdas?: cf.EdgeLambda[];
}

/**
Expand Down Expand Up @@ -223,7 +223,7 @@ export interface AddRoutesOptions {
/**
* Edge lambdas to associate with the API Gateway routes
*/
readonly apigwyEdgeFunctions?: cf.EdgeLambda[];
readonly edgeLambdas?: cf.EdgeLambda[];
}

/**
Expand Down Expand Up @@ -316,7 +316,7 @@ export class MicroAppsCF extends Construct implements IMicroAppsCF {
compress: true,
originRequestPolicy: apigwyOriginRequestPolicy,
viewerProtocolPolicy: cf.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
edgeLambdas: props.apigwyEdgeFunctions,
edgeLambdas: props.edgeLambdas,
};

//
Expand Down Expand Up @@ -422,7 +422,7 @@ export class MicroAppsCF extends Construct implements IMicroAppsCF {
rootPathPrefix,
createAPIPathRoute = true,
createNextDataPathRoute = true,
edgeToOriginLambdas,
edgeLambdas,
} = props;

const apigwyOriginRequestPolicy = MicroAppsCF.createAPIOriginPolicy(this, {
Expand Down Expand Up @@ -464,7 +464,7 @@ export class MicroAppsCF extends Construct implements IMicroAppsCF {
originRequestPolicy: apigwyOriginRequestPolicy,
origin: apiGwyOrigin,
viewerProtocolPolicy: cf.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
edgeLambdas: edgeToOriginLambdas,
edgeLambdas,
},
enableIpv6: true,
priceClass: cf.PriceClass.PRICE_CLASS_100,
Expand All @@ -486,7 +486,7 @@ export class MicroAppsCF extends Construct implements IMicroAppsCF {
rootPathPrefix,
createAPIPathRoute,
createNextDataPathRoute,
apigwyEdgeFunctions: edgeToOriginLambdas,
edgeLambdas,
});

//
Expand Down

0 comments on commit 6a18126

Please sign in to comment.