This section describes how to install, configure and use the Frontend Service Discovery on AWS solution.
- User Guide
The solution is deployed as an AWS CloudFormation template and should take about 5 to 10 minutes to deploy.
Your access to the AWS account must have IAM permissions to launch AWS CloudFormation templates that create IAM roles and to create the solution resources.
Note You are responsible for the cost of the AWS services used while running this solution. For full details, see the pricing pages for each AWS service you will be using in this sample. Prices are subject to change.
- Deploy the latest CloudFormation template using the AWS Console by choosing the "Launch Template" button below for your preferred AWS region. If you wish to deploy using the AWS CLI instead, you can refer to the "Template Link" to download the template files.
Region | Launch Template | Template Link |
---|---|---|
US East (N. Virginia) (us-east-1) | Launch | Link |
US East (Ohio) (us-east-2) | Launch | Link |
US West (Oregon) (us-west-2) | Launch | Link |
Asia Pacific (Mumbai) (ap-south-1) | Launch | Link |
Asia Pacific (Sydney) (ap-southeast-2) | Launch | Link |
Asia Pacific (Tokyo) (ap-northeast-1) | Launch | Link |
EU (Ireland) (eu-west-1) | Launch | Link |
EU (London) (eu-west-2) | Launch | Link |
EU (Frankfurt) (eu-central-1) | Launch | Link |
EU (Stockholm) (eu-north-1) | Launch | Link |
-
If prompted, login using your AWS account credentials.
-
You should see a screen titled "Create Stack" at the "Specify template" step. The fields specifying the CloudFormation template are pre-populated. Choose the Next button at the bottom of the page.
-
On the "Specify stack details" screen you should provide values for the following parameters of the CloudFormation stack:
- Stack Name: (Default: frontend-discovery-service) This is the name that is used to refer to this stack in CloudFormation once deployed.
- AccessControlAllowOrigin: The cors configuration for allow-origin for the consumer API. Specify a domain or
*
to allow all. - CookieSettings: Suffix to be applied by Consumer API when producing the
Set-Cookie
header in case of user not recognized, in order to guarantee stickiness during deployments. Default value isSecure
. For example, if the new user token will beexample123
, the header will be:Set-Cookie: USER_TOKEN=example123; Secure
.
The following parameters are optional and allow further customisation of the solution if required:
- EnableDynamoDBBackups: (Default: false) Whether to enable point in time recovery for the DynamoDB tables.
- Stage: (Default: prod) The stage name used for both APIs.
- LogLevel: (Default: INFO) The log level for Lambda functions deployed for the solution.
- DefaultUserEmail: Optional email for the default user for the Admin API. Leave blank to skip creation.
- CognitoAdvancedSecurity: (Default: OFF) The type of Cognito advanced security to enable.
- DeleteExpiryMinutes: (Default: 1440) How long deleted records (Projects, MicroFrontends) will remain in the system before expiry.
When completed, click Next
-
Configure stack options if desired, then click Next.
-
On the review screen, you must check the boxes for:
- "I acknowledge that AWS CloudFormation might create IAM resources"
- "I acknowledge that AWS CloudFormation might create IAM resources with custom names"
- "I acknowledge that AWS CloudFormation might require the following capability: CAPABILITY_AUTO_EXPAND"
These are required to allow CloudFormation to create a Role to allow access to resources needed by the stack and name the resources in a dynamic way.
-
Choose Create Stack
-
Wait for the CloudFormation stack to launch. Completion is indicated when the "Stack status" is "CREATE_COMPLETE".
- You can monitor the stack creation progress in the "Events" tab.
-
Note the AdminApi and ConsumerApi values displayed in the Outputs tab for the stack. These are used to access the application.
The solution provides an Admin REST API and Consumer API to allow you to integrate it in your own applications.
To add more users to the application:
- Select the Resources tab for your CloudFormation stack and find the UserPool.
- Click the link in the Physical ID column to navigate to the Cognito console for the UserPool
- Select the "Users" tab.
- Use this page to create or manage users. For more information, consult the Managing Users in User Pools Guide.
To use the Admin API directly, you will need to authenticate requests using the Cognito User Pool.
Note the CognitoUserPoolID, CognitoWebClientID and AdminApi parameters displayed in the Outputs tab for the stack.
If you provided a DefaultUserEmail parameter when deploying the stack you will have been emailed a temporary password. Otherwise, you will need to create a user in the AWS Console. You will then need to use the temporary password to set a long term password.
First initiate auth, ensuring the variables are set using the values you took above.
aws cognito-idp admin-initiate-auth \
--user-pool-id $COGNITO_USER_POOL_ID \
--client-id $COGNITO_USER_POOL_CLIENT_ID \
--auth-flow ADMIN_USER_PASSWORD_AUTH \
--auth-parameters USERNAME=$USER_EMAIL_ADDRESS,PASSWORD=$USER_PASSWORD
You will receive a challenge response requiring you to update your password. Send a command like the one below to respond. Fill in session with the value from the response to the previous command. Update USER_PASSWORD variable to a new complex password.
aws cognito-idp admin-respond-to-auth-challenge \
--user-pool-id $COGNITO_USER_POOL_ID \
--client-id $COGNITO_USER_POOL_CLIENT_ID \
--challenge-name NEW_PASSWORD_REQUIRED \
--session $SESSION \
--challenge-responses USERNAME=$USER_EMAIL_ADDRESS,NEW_PASSWORD=$USER_PASSWORD
You will receive an authentication response. For future sessions you can authenticate with the first command above.
Use the IdToken
generated by the previous command to make an authenticated request to the API. For instance, the following command will show a list of existing Projects:
curl $API_URL/projects -H "Authorization: Bearer $ID_TOKEN"
An example of programmatic authentication can be seen in the integration tests.
For more information, consult the Cognito REST API integration guide.
Applications deployed using AWS CloudFormation in the same AWS account and region can integrate with Frontend Service Discovery on AWS by using CloudFormation output values. You can use the solution stack as a nested stack to use its outputs (such as the API URL) as inputs for another application.
Note for using exports: After another stack imports an output value, you can't delete the stack that is exporting the output value or modify the exported output value. All of the imports must be removed before you can delete the exporting stack or modify the output value.
Consult the [exporting stack output values] guide to review the differences between importing exported values and using nested stacks.
When a consumer requests a MicroFrontend by calling the Consumer API, a number of steps are taken to determine which version information to return. This can be broken down into two phases, both of which are detailed below and can be customised as required.
Upon the first request of a Consumer, if a USER_TOKEN
cookie doesn't exist already, the response is returned to them with a Set-Cookie
header, which will therefore persist across numerous requests.
If you will need to work cross-domain, you will need to use Secure; Same-Site=None
as CookieSettings
when deploying the solution, as well as specifying the Frontend's origin as AccessControlAllowOrigin
parameter in order for the cookie setting not to break CORS rules and be correctly persisted.
The above functionality is implemented as a middleware using middy. You can easily write your own middleware if you wish to. Refer to the default code here.
In the case where only one version is currently active, that version will be returned.
Otherwise, the USER_TOKEN
as described above is combined with the current active versions to determine a bucket value from 1-100. The bucket value for the Consumer is compared to the traffic distribution configuration for the MicroFrontend to determine the appropriate version to return. Where there is a deployment and the traffic distribution shifts over time, the Consumer will at some point move onto the new version. As the bucket value is consistent for a given set of active versions, the Consumer will then remain on the new version as the deployment continues.
In the case of any error in this process, the version marked default
will be returned.
The above functionality is implemented here and can be customised as needed.
-
Let's assume we have a Project called
MyWebsite
with IDaa11
and a MicroFrontend calledCatalog
with IDbb22
currently deployed with one active version:1.0.0
. -
If two users with USER_ID
12345
and23456
consume the Consumer API on Prod stage:GET
https://{consumerAPIUrl}/Prod/aa11/microFrontends
they will both receive a response for version1.0.0
ofCatalog
similar to:
{
"schema": "https://raw.githubusercontent.com/awslabs/frontend-discovery/main/schema/v1-pre.json",
"microFrontends": {
"MyWebsite/Catalog": [
{
"metadata": {
"version": "1.0.0",
"integrity": "e0d123e5f317bef78bfdf5a008837200"
},
"fallbackUrl": "https://alt-cdn.com/catalog-1.0.0.js",
"url": "https://static.example.com/catalog-1.0.0.js"
}
]
}
}
- The Admin API is invoked to deploy version
2.0.0
ofCatalog
with aLinear10PercentEvery1Minute
deployment strategy:POST
https://{adminAPIUrl}/Prod/aa11/microFrontends/bb22/versions
with appropriateAuthorization
header and request body:
{
"version": {
"url": "https://static.example.com/catalog-2.0.0.js",
"metadata": {
"version": "2.0.0",
"integrity": "e0d123e5f317bef78bfdf5a008837200"
},
"fallbackUrl": "https://alt-cdn.com/catalog-2.0.0.js"
},
"deploymentStrategy": "Linear10PercentEvery1Minute"
}
-
Immediately and for the next minute, 10% of the users will start seeing version
2.0.0
when making the request described in step 2, while 90% will keep seeing1.0.0
. The platform will do its best to distribute traffic according to configuration, making sure stickiness is guaranteed, so that when user12345
, at some point during the deployment, starts to see version2.0.0
, they will keep seeing the same version for the rest of the deployment. -
After about 10 minutes, the deployment of version
2.0.0
will complete and all users will receive this version.
A deployment can be initiated for a MicroFrontend in two ways:
- When publishing a version, specify a deployment strategy.
- Create a deployment for a previously published Version.
Refer to the API docs for more information.
When a deployment is initiated, the following steps occur:
- A check is performed to ensure there isn’t a deployment already in progress for the same MicroFrontend. If that’s the case, the API returns a 4xx response.
- A set of states are calculated based on the requested Deployment Strategy. The supported strategies are duplicated from AWS SAM options. These states are written to the Deployment DynamoDB table.
- A Step Functions State Machine execution is initiated, the flow of which is detailed below. In short, it applies the calculated states to the MicroFrontend DynamoDB table until the deployment is complete. When the deployment is completed, the
default
property will be updated to the new version.
Usage of the Admin API generates audit logs. These are emitted to CloudWatch Logs under an audit
key. The logs are structured and can therefore be queried using CloudWatch Log Insights. Refer to the below example query as a starting point.
filter ispresent(audit.method)
| fields @timestamp, @logStream, audit.method, audit.user, audit.ipAddress, audit.projectId, audit.microFrontendId, audit.version, audit.deploymentId, audit.statusCode
| sort @timestamp desc
To benefit from the latest features and improvements, you should update the solution deployed to your account when a new version is published. To find out what the latest version is and what has changed since your currently deployed version, check the Changelog.
How you update the solution depends on the difference between versions. If the new version is a minor upgrade (for instance, from version 3.45 to 3.67) you should deploy using a CloudFormation Stack Update. If the new version is a major upgrade (for instance, from 2.34 to 3.0) you may wish to deploy as a new stack and migrate the DynamoDB data across manually.
Major version releases are made in exceptional circumstances and may contain changes that prohibit backward compatibility. Minor versions releases are backward-compatible.
You can find the version of the currently deployed solution by retrieving the
SolutionVersion
output for the solution stack. The solution version is also
shown on the Dashboard of the Web UI.
After reviewing the Changelog, obtain the Template Link
url of the latest
version from "Deploying the Solution" (it will be
similar to
https://solution-builders-us-east-1.s3.us-east-1.amazonaws.com/frontend-discovery-service/latest/template.yaml
).
If you wish to deploy a specific version rather than the latest version, replace
latest
from the url with the chosen version, for instance
https://solution-builders-us-east-1.s3.us-east-1.amazonaws.com/frontend-discovery-service/v0.2/template.yaml
.
To deploy via AWS Console:
-
Open the CloudFormation Console Page and choose the Solution by selecting to the stack's radio button, then choose "Update"
-
Choose "Replace current template" and then input the template URL for the version you wish to deploy in the "Amazon S3 URL" textbox, then choose "Next"
-
On the Stack Details screen, review the Parameters and then choose "Next"
-
On the Configure stack options screen, choose "Next"
-
On the Review stack screen, you must check the boxes for:
- "I acknowledge that AWS CloudFormation might create IAM resources"
- "I acknowledge that AWS CloudFormation might create IAM resources with custom names"
- "I acknowledge that AWS CloudFormation might require the following capability: CAPABILITY_AUTO_EXPAND"
These are required to allow CloudFormation to create a Role to allow access to resources needed by the stack and name the resources in a dynamic way.
-
Choose "Update stack" to start the stack update.
-
Wait for the CloudFormation stack to finish updating. Completion is indicated when the "Stack status" is "UPDATE_COMPLETE".
To deploy via the AWS CLI consult the documentation.
The process for a major upgrade is as follows:
- Create a new stack from scratch.
- Export the data from the old stack to the new stack.
- Migrate users to the new API endpoints.
- Delete the old stack.
The steps for performing this process are:
- Deploy a new instance of the Solution by following the instructions contained in the "Deploying the Solution" section. Make sure you use unique values for Stack Name parameter which differ from existing stack.
- Migrate Data from DynamoDB to ensure the new stack contains the necessary configuration related to MicroFrontends. If your data set is small, it may be easiest to script the transfer of data. Alternatively, you can use S3 Export and then write a script solely for the import.
- Review the Changelog for changes that may affect how you use the new deployment. This may require you to make changes to any software or libraries you have that interacts with the APIs.
- Once all the Admin and Consumer Users are migrated to the new stack, delete the old stack.
To delete a stack via AWS Console:
- Open the CloudFormation Console Page and choose the solution stack, then choose "Delete"
- Once the confirmation modal appears, choose "Delete stack".
- Wait for the CloudFormation stack to finish updating. Completion is indicated when the "Stack status" is "DELETE_COMPLETE".
To delete a stack via the AWS CLI consult the documentation.