Skip to content

Commit c37b0c6

Browse files
[examples] Sync SDK examples from awsdocs/aws-doc-sdk-examples
Includes commit(s): b05a15969c3bbf11358241dd7a1ccfe7e21e246f Co-authored-by: David Souther <[email protected]>
1 parent 6a3cc60 commit c37b0c6

File tree

15 files changed

+4298
-2
lines changed

15 files changed

+4298
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ resolver = "2"
33
exclude = [
44
"examples/test-utils",
55
"examples/examples",
6+
"examples/webassembly",
67
"examples/lambda",
78
"examples/cross_service",
89
"tests/webassembly",

examples/examples/cloudwatchlogs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ path = "../../test-utils"
3232
version = "0.1.0"
3333

3434
[dev-dependencies]
35-
aws-smithy-mocks-experimental= { version = "0.1.1", path = "../../../sdk/aws-smithy-mocks-experimental" }
35+
aws-smithy-mocks-experimental = { version = "0.1.1", path = "../../../sdk/aws-smithy-mocks-experimental" }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build]
2+
target = "wasm32-unknown-unknown"
3+
4+
[target.wasm32-unknown-unknown]
5+
rustflags = ["-C", "target-feature=+atomics"]

examples/webassembly/Cargo.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2+
[package]
3+
name = "aws-wasm"
4+
version = "0.1.0"
5+
authors = ["Eduardo Rodrigues <[email protected]>"]
6+
edition = "2021"
7+
publish = false
8+
9+
[workspace]
10+
11+
[lib]
12+
crate-type = ["cdylib"]
13+
14+
[dependencies]
15+
async-trait = "0.1.63"
16+
console_error_panic_hook = "0.1.7"
17+
http = "0.2.8"
18+
js-sys = "0.3.60"
19+
serde-wasm-bindgen = "0.6.0"
20+
wasm-bindgen = "0.2.83"
21+
wasm-bindgen-futures = "0.4.33"
22+
wasm-timer = "0.2.5"
23+
tracing-wasm = "0.2.1"
24+
tracing = "0.1.37"
25+
aws-config= { version = "1.1.8", path = "../../sdk/aws-config", default-features = false }
26+
aws-credential-types= { version = "1.1.8", path = "../../sdk/aws-credential-types", features = ["hardcoded-credentials"] }
27+
aws-sdk-lambda= { version = "1.17.0", path = "../../sdk/lambda", default-features = false }
28+
aws-smithy-async= { version = "1.1.8", path = "../../sdk/aws-smithy-async" }
29+
aws-smithy-runtime-api= { version = "1.2.0", path = "../../sdk/aws-smithy-runtime-api" }
30+
aws-smithy-types= { version = "1.1.8", path = "../../sdk/aws-smithy-types" }
31+
32+
[dependencies.serde]
33+
version = "1.0.152"
34+
features = ["derive"]
35+
36+
[dependencies.tokio]
37+
version = "1.24.2"
38+
features = ["macros", "rt"]
39+
40+
[dependencies.web-sys]
41+
version = "0.3.60"
42+
features = ["console", "Headers", "Request", "RequestInit", "RequestMode", "Response", "Window"]

examples/webassembly/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# AWS SDK for Rust code examples using WebAssembly
2+
3+
## Purpose
4+
5+
This example demonstrates how to package in a WebAssembly module that uses the AWS SDK for Rust.
6+
7+
## Code examples
8+
9+
- [Show functions](./src/lib.rs) (ListFunctions)
10+
11+
## Running the code examples
12+
13+
### Prerequisites
14+
15+
- 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).
16+
17+
- Install the latest stable version of [Node.js](https://nodejs.org/en/download/).
18+
19+
- Install [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/#).
20+
21+
### ⚠ Important
22+
23+
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.
24+
25+
### count-functions
26+
27+
This example lists your Lambda functions and returns the total amount found in a certain Region.
28+
29+
```
30+
wasm-pack build --target web --out-dir www/pkg --dev
31+
```
32+
33+
From within the [www](./www) directory, run the following command to install project and start serving.
34+
35+
```
36+
npm ci
37+
npm start
38+
```
39+
40+
Access your page at `http://localhost:3000`. Make your selection and press `Run`:
41+
42+
- **region** is the Region in which the client is created.
43+
If not supplied, defaults to **us-west-2**.
44+
- **verbose** displays additional information.
45+
46+
## Resources
47+
48+
- [AWS SDK for Rust repo](https://github.com/awslabs/aws-sdk-rust)
49+
- [AWS SDK for Rust API Reference Guide](https://awslabs.github.io/aws-sdk-rust/aws_sdk_config/index.html)
50+
51+
## Contributing
52+
53+
To propose a new code example to the AWS documentation team,
54+
see [CONTRIBUTING.md](https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/CONTRIBUTING.md).
55+
The team prefers to create code examples that show broad scenarios rather than individual API calls.
56+
57+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

0 commit comments

Comments
 (0)