Skip to content

Commit

Permalink
Refresh and fix some AWS Rust SDK API changes. Notable deprecation: f…
Browse files Browse the repository at this point in the history
…orce_path_style, were we using/needing this, @mmalenic?
  • Loading branch information
brainstorm committed Nov 17, 2023
1 parent 721892c commit 7cfeda2
Show file tree
Hide file tree
Showing 8 changed files with 776 additions and 220 deletions.
937 changes: 745 additions & 192 deletions lib/workload/stateless/filemanager/Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/workload/stateless/filemanager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

The filemanager ingests events from cloud storage like S3 and maintains a queryable table of objects.

This project is split up into multiple crates in a workspace. For development, docker is used, which enables
localstack and a postgres database.
This project is split up into multiple crates in a workspace. For development, docker is used, which enables localstack and a postgres database.

## Prerequisites

Expand All @@ -21,7 +20,8 @@ docker compose up
```

The filemanager uses sqlx to check if queries succeed against a database at compile time.
A `.env` file ensures that the sqlx code can check queries at compile time by providing a `DATABASE_URL`.

A `.env` file ensures that the sqlx code can check queries at compile time by providing a `DATABASE_URL`. If `.env` is not present and there's no active database running and ready to be connected to, this project will fail to compile at all (preventing unnecessary runtime errors).

Filemanager uses docker to run a postgres database to track objects. This means that sqlx connects to the postgres server
running inside the docker compose container. If there are additional postgres installations locally (outside of docker),
Expand Down
6 changes: 3 additions & 3 deletions lib/workload/stateless/filemanager/deploy/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Deployment of filemanager

This folder contains CDK deployment code for filemanager. The CDK code can be deployed locally using
`cdklocal` and `localstack`, or on AWS using `cdk`.
This folder contains CDK deployment code for filemanager. The CDK code can be deployed locally using `cdklocal` and `localstack`, or on AWS using `cdk`:

Run npm install beforehand:

```sh
npm install
npx cdklocal bootstrap
npx cdklocal deploy
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tokio = { version = "1", features = ["macros"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }

axum = "0.6.4"
axum = "0.6"
serde_json = "1.0"

filemanager = { path = "../filemanager" }
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# filemanager-http-lambda

This crate is a Lambda function which ingests events by manually calling the SQS queue receive function.
It is intended to be used behind API gateway.

It is intended to be used behind API gateway.
14 changes: 7 additions & 7 deletions lib/workload/stateless/filemanager/filemanager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ edition.workspace = true

[dependencies]
axum = "0.6"
hyper = { version = "0.14", features = ["full"] }
hyper = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sqlx = { version = "0.7", features = ["postgres", "runtime-tokio", "tls-rustls", "chrono", "uuid"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
utoipa = { version = "3", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "3", features = ["axum"] }
utoipa = { version = "4", features = ["axum_extras"] }
utoipa-swagger-ui = { version = "4", features = ["axum"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
tower = "0.4"
Expand All @@ -26,9 +26,9 @@ async-trait = "0.1"
uuid = { version = "1.4", features = ["v4"] }

# AWS
aws-sdk-sqs = "0.29"
aws-config = "0.56"
aws-sdk-s3 = "0.29"
futures = "0.3.28"
aws-sdk-sqs = "0.37"
aws-config = "0.100"
aws-sdk-s3 = "0.37"
futures = "0.3"
#lambda_http = "0.8.0"
#lambda_runtime = "0.8.0"
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::env;

use aws_config::BehaviorVersion;
use aws_sdk_s3::operation::head_object::{HeadObjectError, HeadObjectOutput};
use aws_sdk_s3::{config, Client};
use aws_sdk_s3::Client;
use chrono::{DateTime, NaiveDateTime, Utc};
use futures::future::join_all;
use tracing::trace;
Expand All @@ -24,22 +25,23 @@ impl S3 {

/// Create with a default S3 client.
pub async fn with_defaults() -> Result<Self> {
let config = aws_config::from_env().load().await;
let mut config = config::Builder::from(&config);
let mut config = aws_config::defaults(BehaviorVersion::latest());

if let Ok(endpoint) = env::var("ENDPOINT_URL") {
trace!("Using endpoint {}", endpoint);
config = config.endpoint_url(endpoint);
}

if let Ok(path_style) = env::var("FORCE_PATH_STYLE") {
if let Ok(path_style) = path_style.parse::<bool>() {
config = config.force_path_style(path_style);
}
}
// TODO: path_style seems to have been deprecated?? Did we need this for something important?
//
// if let Ok(path_style) = env::var("FORCE_PATH_STYLE") {
// if let Ok(path_style) = path_style.parse::<bool>() {
// config = config.force_path_style(path_style);
// }
// }

Ok(Self {
s3_client: Client::from_conf(config.build()),
s3_client: Client::new(&config.load().await),
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::env;

use aws_sdk_sqs::{config, Client};
use aws_config::BehaviorVersion;
use aws_sdk_sqs::Client;
use tracing::trace;

use crate::error::Error::{DbClientError, DeserializeError, SQSReceiveError};
Expand All @@ -26,16 +27,15 @@ impl SQS {

/// Create with a default SQS client.
pub async fn with_default_client() -> Result<Self> {
let config = aws_config::from_env().load().await;
let mut config = config::Builder::from(&config);
let mut config = aws_config::defaults(BehaviorVersion::latest());

if let Ok(endpoint) = env::var("ENDPOINT_URL") {
trace!("Using endpoint {}", endpoint);
config = config.endpoint_url(endpoint);
}

Ok(Self {
sqs_client: Client::from_conf(config.build()),
sqs_client: Client::new(&config.load().await),
sqs_url: std::env::var("SQS_QUEUE_URL")
.map_err(|err| DbClientError(err.to_string()))?,
})
Expand Down

0 comments on commit 7cfeda2

Please sign in to comment.