Skip to content

Commit c45b092

Browse files
committed
deploy: make deployment example work out of the box
1 parent 59a4aa3 commit c45b092

File tree

6 files changed

+102
-41
lines changed

6 files changed

+102
-41
lines changed

deploy/README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ The CDK code in this directory constructs a CDK app from [`HtsgetLambdaStack`][h
1616

1717
These are general settings for the CDK deployment.
1818

19-
| Name | Description | Type |
20-
| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- |
21-
| <span id="config">`config`</span> | The location of the htsget-rs server config. This must be specified. This config file configures the htsget-rs server. See [htsget-config] for a list of available server configuration options. | `string` |
22-
| <span id="domain">`domain`</span> | The domain name for the Route53 Hosted Zone that the htsget-rs server will be under. This must be specified. A hosted zone with this name will either be looked up or created depending on the value of [`lookupHostedZone?`](#lookupHostedZone). | `string` |
23-
| <span id="authorizer">`authorizer`</span> | Deployment options related to the authorizer. Note that this option allows specifying an AWS [JWT authorizer][jwt-authorizer]. The JWT authorizer automatically verifies tokens issued by a Cognito user pool. | [`HtsgetJwtAuthSettings`](#htsgetjwtauthsettings) |
24-
| <span id="subDomain">`subDomain?`</span> | The domain name prefix to use for the htsget-rs server. Together with the [`domain`](#domain), this specifies url that the htsget-rs server will be reachable under. Defaults to `"htsget"`. | `string` |
25-
| <span id="s3BucketResources">`s3BucketResources`</span> | The buckets to serve data from. If this is not specified, this defaults to `[]`. This affects which buckets are allowed to be accessed by the policy actions which are `["s3:List*", "s3:Get*"]`. Note that this option alone does not create buckets, it only gives permission to access them, see the `createS3Buckets` option. This option must be specified to allow `htsget-rs` to access data in the buckets. | `string[]` |
26-
| <span id="lookupHostedZone">`lookupHostedZone?`</span> | Whether to lookup the hosted zone with the domain name. Defaults to `true`. If `true`, attempts to lookup an existing hosted zone using the domain name. Set this to `false` if you want to create a new hosted zone with the domain name. | `boolean` |
27-
| <span id="lookupHostedZone">`createS3Buckets?`</span> | A list of buckets to create. Defaults to no buckets. Buckets are created with [`RemovalPolicy.RETAIN`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.RemovalPolicy.html). This also copies the example data under the `data` directory to those buckets. | `string[]` |
19+
| Name | Description | Type |
20+
|--------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|
21+
| <span id="config">`config`</span> | The location of the htsget-rs server config. This must be specified. This config file configures the htsget-rs server. See [htsget-config] for a list of available server configuration options. | `string` |
22+
| <span id="domain">`domain`</span> | The domain name for the Route53 Hosted Zone that the htsget-rs server will be under. This must be specified. A hosted zone with this name will either be looked up or created depending on the value of [`lookupHostedZone?`](#lookupHostedZone). | `string` |
23+
| <span id="authorizer">`authorizer`</span> | Deployment options related to the authorizer. Note that this option allows specifying an AWS [JWT authorizer][jwt-authorizer]. The JWT authorizer automatically verifies tokens issued by a Cognito user pool. | [`HtsgetJwtAuthSettings`](#htsgetjwtauthsettings) |
24+
| <span id="subDomain">`subDomain?`</span> | The domain name prefix to use for the htsget-rs server. Together with the [`domain`](#domain), this specifies url that the htsget-rs server will be reachable under. Defaults to `"htsget"`. | `string` |
25+
| <span id="s3BucketResources">`s3BucketResources`</span> | The buckets to serve data from. If this is not specified, this defaults to `[]`. This affects which buckets are allowed to be accessed by the policy actions which are `["s3:List*", "s3:Get*"]`. Note that this option does not create buckets, it only gives permission to access them, see the `createS3Buckets` option. This option must be specified to allow `htsget-rs` to access data in buckets that are not created in this stack. | `string[]` |
26+
| <span id="lookupHostedZone">`lookupHostedZone?`</span> | Whether to lookup the hosted zone with the domain name. Defaults to `true`. If `true`, attempts to lookup an existing hosted zone using the domain name. Set this to `false` if you want to create a new hosted zone with the domain name. | `boolean` |
27+
| <span id="createS3Bucket">`createS3Bucket?`</span> | Whether to create a test bucket. Defaults to true. Buckets are created with [`RemovalPolicy.RETAIN`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.RemovalPolicy.html). The correct access permissions are automatically added. | `boolean` |
28+
| <span id="bucketName">`bucketName?`</span> | The name of the bucket created using `createS3Bucket`. The name defaults to an automatically generated CDK name, use this option to override that. This option only has an affect is `createS3Buckets` is true. | `string` |
29+
| <span id="copyTestData">`copyTestData?`</span> | Whether to copy test data into the bucket. Defaults to true. This copies the example data under the `data` directory to those buckets. This option only has an affect is `createS3Buckets` is true. | `boolean` |
2830

2931
#### HtsgetJwtAuthSettings
3032

@@ -70,6 +72,11 @@ npm install
7072

7173
### Deploy to AWS
7274

75+
> [!IMPORTANT]
76+
> The default deployment is designed to work out of the box. A bucket with a CDK-generated name is created with test
77+
> data from the [`data`][data] directory. All deployment settings can be tweaked using the [`settings.ts`][htsget-settings].
78+
> The only option that must be specified in the `domain`, which determines the domain name to serve htsget-rs at.
79+
7380
CDK should be bootstrapped once, if this hasn't been done before:
7481

7582
```sh
@@ -82,6 +89,10 @@ Then to deploy the stack, run:
8289
npx cdk deploy
8390
```
8491

92+
> [!WARNING]
93+
> By default this deployment will create a public instance of htsget-rs. Anyone will be able to query the server
94+
> without authorizing unless you modify the `HtsgetJwtAuthSettings` settings.
95+
8596
### Testing the endpoint
8697

8798
When the deployment is finished, the htsget endpoint can be tested by querying it. If a JWT authorizer is configured,
@@ -176,3 +187,4 @@ and a [MinIO][minio] deployment.
176187
[rust]: https://www.rust-lang.org/tools/install
177188
[zig]: https://ziglang.org/
178189
[zig-getting-started]: https://ziglang.org/learn/getting-started/
190+
[data]: ../data

deploy/bin/settings.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import { HtsgetSettings } from "../lib/htsget-lambda-stack";
44
* Settings to use for the htsget deployment.
55
*/
66
export const SETTINGS: HtsgetSettings = {
7-
config: "config/dev_umccr.toml",
7+
config: "config/example_deploy.toml",
8+
// Specify the domain to serve htsget-rs under.
89
domain: "dev.umccr.org",
910
subDomain: "htsget",
10-
s3BucketResources: [
11-
"arn:aws:s3:::org.umccr.demo.sbeacon-data/*",
12-
"arn:aws:s3:::org.umccr.demo.htsget-rs-data/*",
13-
],
14-
lookupHostedZone: true,
15-
createS3Buckets: [],
11+
s3BucketResources: [],
12+
lookupHostedZone: false,
13+
createS3Bucket: true,
14+
copyTestData: true,
15+
// Override the bucket name.
16+
// bucketName: "bucket",
1617
jwtAuthorizer: {
17-
// Set this to true if you want a public instance.
18+
// Set this to false if you want a private instance.
1819
public: false,
1920
// jwtAudience: ["audience"],
2021
// cogUserPoolId: "user-pool-id",

deploy/config/example_deploy.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ticket_server_cors_allow_headers = "All"
2+
ticket_server_cors_allow_origins = []
3+
ticket_server_cors_allow_methods = "All"
4+
ticket_server_cors_allow_credentials = true
5+
ticket_server_cors_max_age = 300
6+
7+
data_server_enabled = false
8+
9+
name = "umccr-htsget-rs"
10+
version = "0.1"
11+
organization_name = "UMCCR"
12+
organization_url = "https://umccr.org/"
13+
contact_url = "https://umccr.org/"
14+
documentation_url = "https://github.com/umccr/htsget-rs"
15+
environment = "dev"
16+
17+
[[resolvers]]
18+
regex = '^(?P<bucket>.*?)/(?P<key>.*)$'
19+
substitution_string = '$key'
20+
storage = 'S3'

deploy/examples/local_storage/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ curl http://127.0.0.1:8080/reads/data/bam/htsnexus_test_NA12878
1717
```
1818

1919
Which outputs:
20-
2120
```sh
2221
{
2322
"htsget": {

deploy/examples/minio/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
[MinIO][minio] can be used with htsget-rs by configuring the [storage type][storage] as `S3` and setting the `endpoint` to the MinIO server.
44
There are a few specific configuration options that need to be considered to use MinIO with htsget-rs, and those include:
55

6-
- The standard [AWS environment variables][env-variables] for connecting to AWS services must be set, and configured to match those
7-
used by MinIO.
8-
_ This means that htsget-rs expects an `AWS_DEFAULT_REGION` to be set, which must match the region used by MinIO (by default us-east-1).
9-
_ It also means that the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` must be set to match the credentials used by MinIO.
10-
- If using virtual-hosted style [addressing][virtual-addressing] instead of path style [addressing][path-addressing], `MINIO_DOMAIN` must be
11-
set on the MinIO server and DNS resolution must allow accessing the MinIO server using `bucket.<MINIO_DOMAIN>`. \* Path style addressing can be used instead by setting `path_style = true` under the htsget-rs resolvers storage type.
6+
* The standard [AWS environment variables][env-variables] for connecting to AWS services must be set, and configured to match those
7+
used by MinIO.
8+
* This means that htsget-rs expects an `AWS_DEFAULT_REGION` to be set, which must match the region used by MinIO (by default us-east-1).
9+
* It also means that the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` must be set to match the credentials used by MinIO.
10+
* If using virtual-hosted style [addressing][virtual-addressing] instead of path style [addressing][path-addressing], `MINIO_DOMAIN` must be
11+
set on the MinIO server and DNS resolution must allow accessing the MinIO server using `bucket.<MINIO_DOMAIN>`.
12+
* Path style addressing can be used instead by setting `path_style = true` under the htsget-rs resolvers storage type.
1213

1314
The caveats around the addressing style occur because there are two different addressing styles for S3 buckets, path style, e.g.
1415
`http://minio:9000/bucket`, and virtual-hosted style, e.g. `http://bucket.minio:9000`. AWS has declared path style addressing

deploy/lib/htsget-lambda-stack.ts

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { STACK_NAME } from "../bin/htsget-lambda";
22
import * as TOML from "@iarna/toml";
33
import { readFileSync } from "fs";
44

5-
import { Duration, RemovalPolicy, Stack, StackProps, Tags } from "aws-cdk-lib";
5+
import {
6+
CfnOutput,
7+
Duration,
8+
RemovalPolicy,
9+
Stack,
10+
StackProps,
11+
Tags,
12+
} from "aws-cdk-lib";
613
import { Construct } from "constructs";
714

815
import { UserPool } from "aws-cdk-lib/aws-cognito";
@@ -56,10 +63,11 @@ export type HtsgetSettings = {
5663
subDomain?: string;
5764

5865
/**
59-
* The buckets to serve data from. If this is not specified, this defaults to `[]`. This affects which buckets are
60-
* allowed to be accessed by the policy actions which are `["s3:List*", "s3:Get*"]`. Note that this option alone
61-
* does not create buckets, it only gives permission to access them, see the `createS3Buckets` option.
62-
* This option must be specified to allow `htsget-rs` to access data in the buckets.
66+
* The buckets to serve data from. If this is not specified, this defaults to `[]`.
67+
* This affects which buckets are allowed to be accessed by the policy actions which are `["s3:List*", "s3:Get*"]`.
68+
* Note that this option does not create buckets, it only gives permission to access them, see the `createS3Buckets`
69+
* option. This option must be specified to allow `htsget-rs` to access data in buckets that are not created in
70+
* this stack.
6371
*/
6472
s3BucketResources: string[];
6573

@@ -76,11 +84,23 @@ export type HtsgetSettings = {
7684
lookupHostedZone?: boolean;
7785

7886
/**
79-
* A list of buckets to create. Defaults to no buckets. Buckets are created with
87+
* Whether to create a test bucket. Defaults to true. Buckets are created with
8088
* [`RemovalPolicy.RETAIN`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.RemovalPolicy.html).
81-
* This also copies the example data under the `data` directory to those buckets.
89+
* The correct access permissions are automatically added.
90+
*/
91+
createS3Bucket?: boolean;
92+
93+
/**
94+
* The name of the bucket created using `createS3Bucket`. The name defaults to an automatically generated CDK name,
95+
* use this option to override that. This option only has an affect is `createS3Buckets` is true.
96+
*/
97+
bucketName?: string;
98+
99+
/**
100+
* Whether to copy test data into the bucket. Defaults to true. This copies the example data under the `data`
101+
* directory to those buckets. This option only has an affect is `createS3Buckets` is true.
82102
*/
83-
createS3Buckets?: string[];
103+
copyTestData?: boolean;
84104
};
85105

86106
/**
@@ -169,22 +189,26 @@ export class HtsgetLambdaStack extends Stack {
169189
resources: settings.s3BucketResources ?? [],
170190
});
171191

172-
if (settings.createS3Buckets) {
173-
for (const name of settings.createS3Buckets ?? []) {
174-
const bucket = new Bucket(this, "Bucket", {
175-
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
176-
encryption: BucketEncryption.S3_MANAGED,
177-
enforceSSL: true,
178-
removalPolicy: RemovalPolicy.RETAIN,
179-
bucketName: name,
180-
});
192+
if (settings.createS3Bucket) {
193+
const bucket = new Bucket(this, "Bucket", {
194+
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
195+
encryption: BucketEncryption.S3_MANAGED,
196+
enforceSSL: true,
197+
removalPolicy: RemovalPolicy.RETAIN,
198+
bucketName: settings.bucketName,
199+
});
181200

201+
if (settings.copyTestData) {
182202
const dataDir = path.join(__dirname, "..", "..", "data");
183203
new BucketDeployment(this, "DeployFiles", {
184204
sources: [Source.asset(dataDir)],
185205
destinationBucket: bucket,
186206
});
187207
}
208+
209+
s3BucketPolicy.addResources(`arn:aws:s3:::${bucket.bucketName}/*`);
210+
211+
new CfnOutput(this, "HtsgetBucketName", { value: bucket.bucketName });
188212
}
189213

190214
lambdaRole.addManagedPolicy(
@@ -240,6 +264,10 @@ export class HtsgetLambdaStack extends Stack {
240264
jwtAudience: settings.jwtAuthorizer.jwtAudience ?? [],
241265
},
242266
);
267+
} else {
268+
console.warn(
269+
"This will create an instance of htsget-rs that is public! Anyone will be able to query the server without authorization.",
270+
);
243271
}
244272

245273
let hostedZone;

0 commit comments

Comments
 (0)