Skip to content

Commit

Permalink
Update S3 Sample (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 authored Jun 27, 2023
1 parent 1dbc4e9 commit d1bbce9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ cmake -S aws-c-s3 -B aws-c-s3/build -DCMAKE_INSTALL_PREFIX=<install-path> -DCMAK
cmake --build aws-c-s3/build --target install
```

#### Running S3 sample

After installing all the dependencies, and building aws-c-s3, you can run the sample directly from the s3 build directory.

To download:
```
aws-c-s3/build/samples/s3/s3 cp s3://<bucket-name>/<object-name> <download-path> --region <region>
```
To upload:
```
aws-c-s3/build/samples/s3/s3 cp <upload-path> s3://<bucket-name>/<object-name> --region <region>
```
To list objects:
```
aws-c-s3/build/samples/s3/s3 ls s3://<bucket-name> --region <region>
```

## Testing

The unit tests require an AWS account with S3 buckets set up in a particular way.
Expand Down
10 changes: 8 additions & 2 deletions samples/s3/s3-cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,16 @@ static bool s_are_all_transfers_and_listings_done(void *arg) {
}

void s_on_object_list_finished(struct aws_s3_paginator *paginator, int error_code, void *user_data) {
(void)error_code;

struct cp_app_ctx *cp_app_ctx = user_data;

if (error_code != AWS_OP_SUCCESS) {
fprintf(
stderr,
"Failure while listing objects. Please check if you have valid credentials and s3 path is correct. Error: "
"%s\n",
aws_error_debug_str(error_code));
exit(1);
}
if (aws_s3_paginator_has_more_results(paginator)) {
aws_s3_paginator_continue(paginator, &cp_app_ctx->app_ctx->signing_config);
} else {
Expand Down
7 changes: 7 additions & 0 deletions samples/s3/s3-ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ void s_on_list_finished(struct aws_s3_paginator *paginator, int error_code, void
}
return;
}
} else {
fprintf(
stderr,
"Failure while listing objects. Please check if you have valid credentials and s3 path is correct. "
"Error: "
"%s\n",
aws_error_debug_str(error_code));
}

/* all pages received. triggers the condition variable to exit the application. */
Expand Down

0 comments on commit d1bbce9

Please sign in to comment.