|
1 |
| -# AWS SDK for Go (v2) code examples |
| 1 | +# SDK for Go V2 code examples |
2 | 2 |
|
3 | 3 | ## Overview
|
4 | 4 |
|
5 |
| -The code examples in this topic show you how to use the AWS SDK for Go (v2) with AWS. |
| 5 | +The code examples in this topic show you how to use the AWS SDK for Go V2 with AWS. |
6 | 6 |
|
7 |
| -The AWS SDK for Go (v2) provides a Go API for AWS infrastructure services. Using the |
| 7 | +The SDK for Go V2 provides a Go API for AWS infrastructure services. Using the |
8 | 8 | SDK, you can build applications on top of Amazon S3, Amazon EC2, Amazon DynamoDB,
|
9 | 9 | and more.
|
10 | 10 |
|
@@ -42,7 +42,24 @@ A README in each folder describes how to run the example.
|
42 | 42 | * You must have an AWS account, and have your default credentials and AWS Region
|
43 | 43 | configured as described in the
|
44 | 44 | [AWS Tools and SDKs Shared Configuration and Credentials Reference Guide](https://docs.aws.amazon.com/credref/latest/refdocs/creds-config-files.html).
|
45 |
| -* Go 1.18 or later |
| 45 | +* [Go 1.18 or later](https://go.dev/doc/install) |
| 46 | + |
| 47 | +### Run the code |
| 48 | + |
| 49 | +Each example is a Go module that typically contains two packages that you can run: |
| 50 | +`hello` and `cmd`. The `hello` package makes a single call to a service to verify that you |
| 51 | +can use the service with the SDK. The `cmd` package runs more complex scenarios |
| 52 | +to show you how to accomplish specific tasks. |
| 53 | + |
| 54 | +For example, run the `hello` package from the command line: |
| 55 | + |
| 56 | +``` |
| 57 | +go run ./hello |
| 58 | +``` |
| 59 | + |
| 60 | +Some examples require command line arguments. In these cases, you can run the example |
| 61 | +with a `-h` flag to get help. Each example has a README.md that describes additional |
| 62 | +specifics about how to run the example and any other prerequisites. |
46 | 63 |
|
47 | 64 | ## Tests
|
48 | 65 |
|
@@ -80,16 +97,53 @@ go test -tags=integration ./...
|
80 | 97 | ```
|
81 | 98 |
|
82 | 99 | ## Docker image (Beta)
|
| 100 | + |
83 | 101 | This example code will soon be available in a container image
|
84 |
| -hosted on [Amazon Elastic Container Registry (ECR)](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html). This image will be pre-loaded |
85 |
| -with all Golang examples with dependencies pre-resolved, allowing you to explore |
86 |
| -these examples in an isolated environment. |
| 102 | +hosted on [Amazon Elastic Container Registry (Amazon ECR)](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html). |
| 103 | +The image will be preloaded with all Go examples, with dependencies pre-resolved. |
| 104 | +That way, you can explore the examples in an isolated environment. |
87 | 105 |
|
88 |
| -⚠️ As of January 2023, the [SDK for Go v2 image](https://gallery.ecr.aws/b4v4v1s0/dotnetv3) is available on ECR Public but is still |
89 |
| -undergoing active development. Refer to |
90 |
| -[this GitHub issue](https://github.com/awsdocs/aws-doc-sdk-examples/issues/4129) |
| 106 | +⚠️ As of January 2023, the [SDK for Go V2 image](https://gallery.ecr.aws/b4v4v1s0/gov2) is available in the Amazon ECR Public Gallery but is still undergoing active development. Refer to [this GitHub issue](https://github.com/awsdocs/aws-doc-sdk-examples/issues/4125) |
91 | 107 | for more information.
|
92 | 108 |
|
| 109 | +### Build the Docker image |
| 110 | + |
| 111 | +1. Install and run Docker on your machine. |
| 112 | +2. Navigate to the same directory as this README. |
| 113 | +3. Run `docker build -t <image_name> .` and replace `image_name` with a name for the image. |
| 114 | + |
| 115 | +### Launch the Docker container |
| 116 | + |
| 117 | +Run the Docker container with your image using the following command: |
| 118 | + |
| 119 | +**Windows** |
| 120 | + |
| 121 | +``` |
| 122 | +docker run -it --volume %USERPROFILE%\.aws:/root/.aws <image_name> |
| 123 | +``` |
| 124 | + |
| 125 | +**macOS or Linux** |
| 126 | +``` |
| 127 | +docker run -it -v ~/.aws/credentials:/root/.aws/credentials <image_name> |
| 128 | +``` |
| 129 | + |
| 130 | +The terminal initiates a bash instance at the root of the container. |
| 131 | +The Go code examples are in the `gov2` folder and can be run by following |
| 132 | +the instructions in the READMEs in the various folders. |
| 133 | + |
| 134 | +### Run tests in the Docker container |
| 135 | + |
| 136 | +To run all unit tests and write the output to a file, run the following command |
| 137 | +in the `gov2` directory of the container: |
| 138 | + |
| 139 | +``` |
| 140 | +./run_all_tests.sh |
| 141 | +``` |
| 142 | + |
| 143 | +To run integration tests, pass an `integration` argument to the `run_all_tests.sh` |
| 144 | +script. Integration tests create and destroy AWS resources and will incur charges on your account. |
| 145 | +Proceed with caution. |
| 146 | + |
93 | 147 | ## Additional resources
|
94 | 148 |
|
95 | 149 | * [AWS SDK for Go (v2) Developer Guide](https://aws.github.io/aws-sdk-go-v2/docs/)
|
|
0 commit comments