Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Simpler lambda invoke example with AWS SAM cli #3

Merged
merged 19 commits into from Sep 30, 2020

Conversation

brainstorm
Copy link
Owner

@brainstorm brainstorm commented Sep 25, 2020

Try to simplify the DX further by using SAM cli. TL;DR is:

$ aws sso login (or whatever way you have to load your AWS your creds)
(edit `event.json` to your liking)
$ cp ./target/x86_64-unknown-linux-musl/release/bootstrap .
$ sam local invoke -e event.json

Enjoy!

@brainstorm brainstorm marked this pull request as ready for review September 25, 2020 05:54
README.md Show resolved Hide resolved
Type: AWS::Serverless::Function
Properties:
FunctionName: htsget-aws
Handler: foo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does foo bind to the right handler? Or is this value essentially unused for Rust?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a really good question! I guess that for the provided runtime the handler might not matter because it just goes straight to bootstrap and then that binary's ELF entrypoint (entry0?)... just guessing though and haven not tested deploy, just local invoke... perhaps it does matter in the former?

README.md Outdated Show resolved Hide resolved
@brainstorm
Copy link
Owner Author

Right now it prints bytes instead of target_names... the to_hashmap() is giving me some headaches w/ serde and serialization... could you give it a quick peek at it @andrewpatto? Namely:

(base) rvalls@umccr s3-rust-htslib-bam % git diff
diff --git a/src/main.rs b/src/main.rs
index b9f54d1..e132432 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -34,7 +34,7 @@ async fn bam_header(event: Value, _: Context) -> Result<Value, Error> {

     // Get some lowlevel libcurl action on hfile_curl/s3 from htslib and fetch the header
     let bam = bam::Reader::from_url(&s3_url).unwrap();
-    let header = bam::Header::from_template(bam.header()).to_bytes();
+    let header = bam::Header::from_template(bam.header()).to_hashmap();

     // and return the array as a JSON object
     Ok(json!(header))

After that, this PR is totally mergeable and super easy to deploy, thanks a lot for all the effort and attention :)

src/main.rs Outdated
return reader.unwrap().target_names();
// convert the header to an array of strings so we can better see the result
let header_string = String::from_utf8(header.to_bytes()).unwrap();
let header_strings: Vec<&str> = header_string.split("\n").collect();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is relatively simple and kind of at least gives the returned JSON object some structure thats meaningful

@andrewpatto
Copy link
Collaborator

andrewpatto commented Sep 30, 2020

There appears to be a bug in to_hashmap() for the CRAM files in the example (from a brief look I think the COmment lines are failing to match the expected format in the to_hashmap() regex)

"@co\tFASTQ=ERR009378_1.fastq.gz"

For the sake of the example I've just changed it to split the header by lines which should be fine as an example..

Use lines not split
@brainstorm
Copy link
Owner Author

Thanks a ton for this @andrewpatto :)

@brainstorm brainstorm merged commit 37e9b50 into master Sep 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants