Skip to content

Commit

Permalink
[examples] Sync SDK examples from awsdocs/aws-doc-sdk-examples
Browse files Browse the repository at this point in the history
Includes commit(s):
  b05a15969c3bbf11358241dd7a1ccfe7e21e246f

Co-authored-by: David Souther <davidsouther+github@gmail.com>
  • Loading branch information
aws-sdk-rust-ci and DavidSouther committed Mar 18, 2024
1 parent 6a3cc60 commit c37b0c6
Show file tree
Hide file tree
Showing 15 changed files with 4,298 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
exclude = [
"examples/test-utils",
"examples/examples",
"examples/webassembly",
"examples/lambda",
"examples/cross_service",
"tests/webassembly",
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/cloudwatchlogs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ path = "../../test-utils"
version = "0.1.0"

[dev-dependencies]
aws-smithy-mocks-experimental= { version = "0.1.1", path = "../../../sdk/aws-smithy-mocks-experimental" }
aws-smithy-mocks-experimental = { version = "0.1.1", path = "../../../sdk/aws-smithy-mocks-experimental" }
5 changes: 5 additions & 0 deletions examples/webassembly/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
target = "wasm32-unknown-unknown"

[target.wasm32-unknown-unknown]
rustflags = ["-C", "target-feature=+atomics"]
42 changes: 42 additions & 0 deletions examples/webassembly/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
[package]
name = "aws-wasm"
version = "0.1.0"
authors = ["Eduardo Rodrigues <16357187+eduardomourar@users.noreply.github.com>"]
edition = "2021"
publish = false

[workspace]

[lib]
crate-type = ["cdylib"]

[dependencies]
async-trait = "0.1.63"
console_error_panic_hook = "0.1.7"
http = "0.2.8"
js-sys = "0.3.60"
serde-wasm-bindgen = "0.6.0"
wasm-bindgen = "0.2.83"
wasm-bindgen-futures = "0.4.33"
wasm-timer = "0.2.5"
tracing-wasm = "0.2.1"
tracing = "0.1.37"
aws-config= { version = "1.1.8", path = "../../sdk/aws-config", default-features = false }
aws-credential-types= { version = "1.1.8", path = "../../sdk/aws-credential-types", features = ["hardcoded-credentials"] }
aws-sdk-lambda= { version = "1.17.0", path = "../../sdk/lambda", default-features = false }
aws-smithy-async= { version = "1.1.8", path = "../../sdk/aws-smithy-async" }
aws-smithy-runtime-api= { version = "1.2.0", path = "../../sdk/aws-smithy-runtime-api" }
aws-smithy-types= { version = "1.1.8", path = "../../sdk/aws-smithy-types" }

[dependencies.serde]
version = "1.0.152"
features = ["derive"]

[dependencies.tokio]
version = "1.24.2"
features = ["macros", "rt"]

[dependencies.web-sys]
version = "0.3.60"
features = ["console", "Headers", "Request", "RequestInit", "RequestMode", "Response", "Window"]
57 changes: 57 additions & 0 deletions examples/webassembly/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# AWS SDK for Rust code examples using WebAssembly

## Purpose

This example demonstrates how to package in a WebAssembly module that uses the AWS SDK for Rust.

## Code examples

- [Show functions](./src/lib.rs) (ListFunctions)

## Running the code examples

### Prerequisites

- You must have an AWS account, and have configured your default credentials and AWS Region as described in [https://github.com/awslabs/aws-sdk-rust](https://github.com/awslabs/aws-sdk-rust).

- Install the latest stable version of [Node.js](https://nodejs.org/en/download/).

- Install [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/#).

### ⚠ Important

Your must customize your AWS credentials in the file [www/env/credentials.js](./www/env/credentials.js). Otherwise, it will not make the request to the backend.

### count-functions

This example lists your Lambda functions and returns the total amount found in a certain Region.

```
wasm-pack build --target web --out-dir www/pkg --dev
```

From within the [www](./www) directory, run the following command to install project and start serving.

```
npm ci
npm start
```

Access your page at `http://localhost:3000`. Make your selection and press `Run`:

- **region** is the Region in which the client is created.
If not supplied, defaults to **us-west-2**.
- **verbose** displays additional information.

## Resources

- [AWS SDK for Rust repo](https://github.com/awslabs/aws-sdk-rust)
- [AWS SDK for Rust API Reference Guide](https://awslabs.github.io/aws-sdk-rust/aws_sdk_config/index.html)

## Contributing

To propose a new code example to the AWS documentation team,
see [CONTRIBUTING.md](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/CONTRIBUTING.md).
The team prefers to create code examples that show broad scenarios rather than individual API calls.

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0
Loading

0 comments on commit c37b0c6

Please sign in to comment.