Skip to content

Commit 59a4aa3

Browse files
committed
deploy: add option to create buckets with test data and clarify docs
1 parent d2b018f commit 59a4aa3

File tree

8 files changed

+266
-133
lines changed

8 files changed

+266
-133
lines changed

deploy/README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,27 @@ The CDK code in this directory constructs a CDK app from [`HtsgetLambdaStack`][h
1313
[`bin/settings.ts`][htsget-settings]:
1414

1515
#### HtsgetSettings
16+
1617
These are general settings for the CDK deployment.
1718

18-
| Name | Description | Type |
19-
|----------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|
20-
| <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` |
21-
| <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` |
22-
| <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) |
23-
| <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` |
24-
| <span id="s3BucketResources">`s3BucketResources?`</span> | The resources that are affected by the bucket policy with actions: `["s3:List*", "s3:Get*"]`. If this is not specified, it defaults to `["arn:aws:s3:::*"]`. This affects which buckets are allowed to be accessed with the policy. | `string[]` |
25-
| <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` |
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[]` |
2628

2729
#### HtsgetJwtAuthSettings
30+
2831
These settings are used to determine if the htsget API gateway endpoint is configured to have a JWT authorizer or not.
2932

3033
| Name | Description | Type |
31-
|---------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|------------|
34+
| ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
3235
| <span id="public">`public`</span> | Whether this deployment is public. If this is `true` then no authorizer is present on the API gateway and the options below have no effect. | `boolean` |
33-
| <span id="jwtAudience">`jwtAudience?`</span> | A list of the intended recipients of the JWT. A valid JWT must provide an aud that matches at least one entry in this list. | `string[]` |
36+
| <span id="jwtAudience">`jwtAudience?`</span> | A list of the intended recipients of the JWT. A valid JWT must provide an aud that matches at least one entry in this list. | `string[]` |
3437
| <span id="cogUserPoolId?">`cogUserPoolId?`</span> | The cognito user pool id for the authorizer. If this is not set, then a new user pool is created. No user pool is created if [`public`](#public) is true. | `string` |
3538

3639
The [`HtsgetSettings`](#htsgetsettings) are passed into [`HtsgetLambdaStack`][htsget-lambda-stack] in order to change the deployment config. An example of a public instance deployment
@@ -49,7 +52,7 @@ After installing the basic dependencies, complete the following steps:
4952

5053
1. Login to AWS and define `CDK_DEFAULT_*` env variables (if not defined already). You must be authenticated with your AWS cloud to run this step.
5154
2. Install [cargo-lambda], as it is used to compile artifacts that are uploaded to aws lambda.
52-
3. Define which configuration to use for htsget-rs as stated in the configuration section.
55+
3. Define which configuration to use for htsget-rs as stated in the configuration section.
5356

5457
Below is a summary of commands to run in this directory:
5558

deploy/bin/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const SETTINGS: HtsgetSettings = {
1212
"arn:aws:s3:::org.umccr.demo.htsget-rs-data/*",
1313
],
1414
lookupHostedZone: true,
15+
createS3Buckets: [],
1516
jwtAuthorizer: {
1617
// Set this to true if you want a public instance.
1718
public: false,

deploy/config/dev_umccr.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ contact_url = "https://umccr.org/"
2323
documentation_url = "https://github.com/umccr/htsget-rs"
2424
environment = "dev"
2525

26+
[[resolvers]]
27+
regex = '^(org.umccr.dev.htsget-rs-test-data)/(?P<key>.*)$'
28+
substitution_string = '$key'
29+
storage = 'S3'
30+
2631
[[resolvers]]
2732
regex = '^(umccr-10c-data-dev)/(?P<key>.*)$'
2833
substitution_string = '$key'

deploy/examples/local_storage/README.md

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

1919
Which outputs:
20+
2021
```sh
2122
{
2223
"htsget": {
@@ -41,4 +42,4 @@ default settings, and `curl http://127.0.0.1:8080/reads/data/<id>`, noting the e
4142

4243
[local]: ../../../htsget-config/README.md#resolvers
4344
[compose]: compose.yml
44-
[data]: ../../../data
45+
[data]: ../../../data

deploy/examples/minio/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
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>`.
12-
* 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>`. \* Path style addressing can be used instead by setting `path_style = true` under the htsget-rs resolvers storage type.
1312

1413
The caveats around the addressing style occur because there are two different addressing styles for S3 buckets, path style, e.g.
1514
`http://minio:9000/bucket`, and virtual-hosted style, e.g. `http://bucket.minio:9000`. AWS has declared path style addressing
16-
as [deprecated][path-style-deprecated], so this example sets up virtual-hosted style addressing as the default.
15+
as [deprecated][path-style-deprecated], so this example sets up virtual-hosted style addressing as the default.
1716

1817
## Deployment using Docker
1918

@@ -36,6 +35,7 @@ curl http://127.0.0.1:8080/reads/bam/htsnexus_test_NA12878
3635
```
3736

3837
Outputs:
38+
3939
```sh
4040
{
4141
"htsget": {
@@ -68,4 +68,4 @@ docker exec -it minio curl -H "Range: bytes=0-2596770" "http://data.minio:9000/b
6868
[virtual-addressing]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#virtual-hosted-style-access
6969
[path-addressing]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#path-style-access
7070
[compose]: compose.yml
71-
[data]: ../../../data
71+
[data]: ../../../data

deploy/lib/htsget-lambda-stack.ts

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

5-
import { Duration, Stack, StackProps, Tags } from "aws-cdk-lib";
5+
import { Duration, RemovalPolicy, Stack, StackProps, Tags } from "aws-cdk-lib";
66
import { Construct } from "constructs";
77

88
import { UserPool } from "aws-cdk-lib/aws-cognito";
99
import {
10+
ManagedPolicy,
11+
PolicyStatement,
1012
Role,
1113
ServicePrincipal,
12-
PolicyStatement,
13-
ManagedPolicy,
1414
} from "aws-cdk-lib/aws-iam";
1515
import { Architecture } from "aws-cdk-lib/aws-lambda";
1616
import {
@@ -29,6 +29,12 @@ import {
2929
HttpMethod,
3030
} from "aws-cdk-lib/aws-apigatewayv2";
3131
import { HttpJwtAuthorizer } from "aws-cdk-lib/aws-apigatewayv2-authorizers";
32+
import {
33+
BlockPublicAccess,
34+
Bucket,
35+
BucketEncryption,
36+
} from "aws-cdk-lib/aws-s3";
37+
import { BucketDeployment, Source } from "aws-cdk-lib/aws-s3-deployment";
3238

3339
/**
3440
* Settings related to the htsget lambda stack.
@@ -50,10 +56,12 @@ export type HtsgetSettings = {
5056
subDomain?: string;
5157

5258
/**
53-
* Policies to add to the bucket. If this is not specified, this defaults to `["arn:aws:s3:::*"]`.
54-
* This affects which buckets are allowed to be accessed by the policy actions which are `["s3:List*", "s3:Get*"]`.
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.
5563
*/
56-
s3BucketResources?: string[];
64+
s3BucketResources: string[];
5765

5866
/**
5967
* Whether this deployment is gated behind a JWT authorizer, or if its public.
@@ -66,6 +74,13 @@ export type HtsgetSettings = {
6674
* domain name.
6775
*/
6876
lookupHostedZone?: boolean;
77+
78+
/**
79+
* A list of buckets to create. Defaults to no buckets. Buckets are created with
80+
* [`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.
82+
*/
83+
createS3Buckets?: string[];
6984
};
7085

7186
/**
@@ -151,9 +166,27 @@ export class HtsgetLambdaStack extends Stack {
151166

152167
const s3BucketPolicy = new PolicyStatement({
153168
actions: ["s3:List*", "s3:Get*"],
154-
resources: settings.s3BucketResources ?? ["arn:aws:s3:::*"],
169+
resources: settings.s3BucketResources ?? [],
155170
});
156171

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+
});
181+
182+
const dataDir = path.join(__dirname, "..", "..", "data");
183+
new BucketDeployment(this, "DeployFiles", {
184+
sources: [Source.asset(dataDir)],
185+
destinationBucket: bucket,
186+
});
187+
}
188+
}
189+
157190
lambdaRole.addManagedPolicy(
158191
ManagedPolicy.fromAwsManagedPolicyName(
159192
"service-role/AWSLambdaBasicExecutionRole",

0 commit comments

Comments
 (0)