Deploy your project
A deploy
of your application uses aws-cdk
to inspect your local build and automatically provision all of the necessary AWS resources as a single CloudFormation stack.
This includes:
- S3 storage buckets for publishing datasources and containing bundled Report UI components
- Lambda functions that run preprocessing and geoprocessing functions on-demand
- A Gateway with REST API and Web Socket API for clients like SeaSketch to discover, access, and run all project resources over the Internet.
- A DynamoDB database for caching function results
For every deploy after the first, it is smart enough to compute the changeset between your local build and the published stack and modify the stack automatically.
Setup AWS
You are not required to complete this step until you want to deploy your project and integrate it with SeaSketch. Until then, you can do everything except publish
data or deploy
your project.
You will need to create an AWS account with an admin user, allowing the framework to deploy your project using CloudFormation. A payment method such as a credit card will be required.
Expected cost: free to a few dollars per month. You will be able to track this.
- Create an Amazon [AWS account] such that you can login and access the main AWS Console page (https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/).
- Create an AWS IAM admin account. This is what you will use to manage projects.
AWSCLI
If you are using a Docker devcontaine to develop reports you should already have access to the aws
command. But if you are running directly on your host operating system you will need to install AWS CLI and configure it with your IAM account credentials.
Extra steps for Windows
Windows you have the option of installing awscli for Windows and then exposing your credentials in your Ubuntu container. This allows you to manage one set of credentials.
Assuming your username is alex
, once you've installed awscli in Windows, confirm you now have the following files under Windows.
C:\Users\alex\.aws\credentials
C:\Users\alex\.aws\config
Now, open a Ubuntu shell and edit your bash environment variables to point to those files.
Add the following to your startup .bashrc
file.
export AWS_SHARED_CREDENTIALS_FILE=/mnt/c/Users/alex/.aws/credentials
export AWS_CONFIG_FILE=/mnt/c/Users/alex/.aws/config
Now, verify the environment variables are set
source ~/.bashrc
echo $AWS_SHARED_CREDENTIALS_FILE
echo $AWS_CONFIG_FILE
Confirm awscli is working
To check if awscli is configured run the following:
aws configure list
If no values are listed, then the AWS CLI is not configured properly. Go back and check everything over for this step.
Do the deploy
To deploy your project run the following:
npm run deploy
When the command completes, the stack should now be deployed. It should print out a list of URL's for accessing stack resources. You do not need to write these down. You can run the npm run url
command at any time and it will output the RestApiUrl, which is the main URL you care about for integration with SeaSketch. After deploy a cdk-outputs.json
file will also have been generated in the top-level directory of your project with the full list of URL's. This file is not checked into the code repository.
Example:
{
"gp-fsm-reports-test": {
"clientDistributionUrl": "abcdefg.cloudfront.net",
"clientBucketUrl": "https://s3.us-west-2.amazonaws.com/gp-fsm-reports-test-client",
"datasetBucketUrl": "https://s3.us-west-2.amazonaws.com/gp-fsm-reports-test-datasets",
"GpRestApiEndpointBF901973": "https://tuvwxyz.execute-api.us-west-2.amazonaws.com/prod/",
"restApiUrl": "https://tuvwxyz.execute-api.us-west-2.amazonaws.com/prod/",
"socketApiUrl": "wss://lmnop.execute-api.us-west-2.amazonaws.com"
}
}
Debugging deploy
- If your AWS credentials are not setup and linked properly, you will get an error here. Go back and fix it.
- The very first time you deploy any project to a given AWS data center (e.g. us-west-1), it may ask you to bootstrap cdk first. Simply run the following:
npm run bootstrap
Then deploy
again.
- If your deploy fails and it's not the first time you deployed, it may tell you it has performed a
Rollback
on the deployed stack to its previous state. This may or may not be successful. You'll want to verify that your project is still working properly within SeaSketch. If it's not you can always destroy your stack by running:
npm run destroy
Once complete, you will need to build
and deploy
again.
Publish your datasources
Once you have deployed your project to AWS, it will have an S3 bucket for publishing datasources
to.
Your datasources will need to have already been imported using import:data
and exist in data/dist for this to work.
npm run publish:data
It will ask you if you want to publish all datasources, or choose from a list.
- Note if you don't publish your datasources, then your smoke tests may work properly, but your geoprocessing functions will throw file not found errors in production.
Integrating Your Project with SeaSketch
Once you've deployed your project, you will find a file called cdk.outputs
which contains the URL to the service manifest for your project.
"restApiUrl": "https://xxxyyyyzzz.execute-api.us-west-2.amazonaws.com/prod/",
Now follow the SeaSketch instructions to assign services to each of your sketch classes.
If your sketch class is a Polygon or other feature type, you should assign it both a preprocessing function (for clipping) and a report client. If you installed the template-ocean-eez
starter template then your preprocessor is called clipToOceanEez
and report client is named MpaTabReport
.
If your sketch class is a collection then you only need to assign it a report client. Since we build report clients that work on both individual sketches and sketch collections, you can assign the same report client to your collection as you assigned to your individual sketch class(es).
This should give you the sense that you can create different report clients for different sketch classes within the same project. Or even make reports for sketch collections completely different from reports for individual sketches.
Create a sketch and run your reports to make sure it all works!