Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update deployment README #251

Merged
merged 4 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,41 @@ can be found under [`bin/htsget-lambda.ts`][htsget-lambda-bin]. This uses the [`
### Prerequisites

1. [aws-cli] should be installed and authenticated in the shell.
1. Node.js and [npm] should be installed.
1. [Rust][rust] should be installed.
1. [Zig][zig] should be installed
2. Node.js and [npm] should be installed.
3. [Rust][rust] should be installed.
4. [Zig][zig] should be installed. Zig can be installed by running `cargo lambda build` at least once.

After installing the basic dependencies, complete the following steps:

1. Define CDK\_DEFAULT\_* env variables (if not defined already). You must be authenticated with your AWS cloud to run this step.
1. Add the arm cross-compilation target to rust.
1. Install [cargo-lambda], as it is used to compile artifacts that are uploaded to aws lambda.
1. Define which configuration to use for htsget-rs on `cdk.json` as stated in aforementioned configuration section.
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.
2. Install [cargo-lambda], as it is used to compile artifacts that are uploaded to aws lambda.
3. Define which configuration to use for htsget-rs as stated in the configuration section.

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

```sh
``export CDK_DEFAULT_ACCOUNT=`aws sts get-caller-identity --query Account --output text`
export CDK_DEFAULT_REGION=`aws configure get region```
rustup target add aarch64-unknown-linux-gnu
cargo install cargo-lambda

## Install zig if not already installed.
#cd .. && cargo lambda build && cd deploy

export CDK_DEFAULT_ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
export CDK_DEFAULT_REGION=$(aws configure get region)

npm install
```

### Deploy to AWS

CDK should be bootstrapped once, if this hasn't been done before.
CDK should be bootstrapped once, if this hasn't been done before:

```sh
npx cdk bootstrap
```

In order to deploy, check that the stack synthesizes correctly and then deploy.
Then to deploy the stack, run:

```sh
npx cdk synth
npx cdk deploy
```

Expand Down
2 changes: 1 addition & 1 deletion deploy/bin/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export const SETTINGS: HtsgetSettings = {
// Set this to true if you want a public instance.
public: false,
// jwtAudience: ["audience"],
// cogUserPoolId: "user-pool-id"
// cogUserPoolId: "user-pool-id",
},
};
44 changes: 20 additions & 24 deletions deploy/lib/htsget-lambda-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { readFileSync } from "fs";

import { Duration, Stack, StackProps, Tags } from "aws-cdk-lib";
import { Construct } from "constructs";
import { RustFunction, Settings } from "rust.aws-cdk-lambda";

import { UserPool } from "aws-cdk-lib/aws-cognito";
import {
Expand All @@ -14,20 +13,22 @@ import {
ManagedPolicy,
} from "aws-cdk-lib/aws-iam";
import { Architecture } from "aws-cdk-lib/aws-lambda";
import {
CorsHttpMethod,
HttpMethod,
HttpApi,
DomainName,
} from "@aws-cdk/aws-apigatewayv2-alpha";
import { HttpLambdaIntegration } from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
import { HttpJwtAuthorizer } from "@aws-cdk/aws-apigatewayv2-authorizers-alpha";
import {
Certificate,
CertificateValidation,
} from "aws-cdk-lib/aws-certificatemanager";
import { ARecord, HostedZone, RecordTarget } from "aws-cdk-lib/aws-route53";
import { ApiGatewayv2DomainProperties } from "aws-cdk-lib/aws-route53-targets";
import { RustFunction } from "cargo-lambda-cdk";
import path from "path";
import { HttpLambdaIntegration } from "aws-cdk-lib/aws-apigatewayv2-integrations";
import {
CorsHttpMethod,
DomainName,
HttpApi,
HttpMethod,
} from "aws-cdk-lib/aws-apigatewayv2";
import { HttpJwtAuthorizer } from "aws-cdk-lib/aws-apigatewayv2-authorizers";

/**
* Settings related to the htsget lambda stack.
Expand Down Expand Up @@ -160,29 +161,24 @@ export class HtsgetLambdaStack extends Stack {
);
lambdaRole.addToPolicy(s3BucketPolicy);

// Set the workspace directory of htsget.
Settings.WORKSPACE_DIR = "../";
// Don't build htsget packages other than htsget-lambda.
Settings.BUILD_INDIVIDUALLY = true;

let htsgetLambda = new RustFunction(this, id + "Function", {
// Build htsget-lambda only.
package: "htsget-lambda",
target: "aarch64-unknown-linux-gnu",

manifestPath: path.join(__dirname, "..", ".."),
binaryName: "htsget-lambda",
bundling: {
environment: {
RUSTFLAGS: "-C target-cpu=neoverse-n1",
CARGO_PROFILE_RELEASE_LTO: "true",
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: "1",
},
cargoLambdaFlags: ["--features", "s3-storage"],
},
memorySize: 128,
timeout: Duration.seconds(28),
environment: {
...config.htsgetConfig,
RUST_LOG:
"info,htsget_http_lambda=trace,htsget_config=trace,htsget_http_core=trace,htsget_search=trace",
},
features: ["s3-storage"],
buildEnvironment: {
RUSTFLAGS: "-C target-cpu=neoverse-n1",
CARGO_PROFILE_RELEASE_LTO: "true",
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: "1",
},
architecture: Architecture.ARM_64,
role: lambdaRole,
});
Expand Down
Loading
Loading