The code examples in this topic show you how to use the AWS SDK for .NET 3.x with AWS.
The AWS SDK for .NET 3.x provides a .NET API for AWS infrastructure services. Using the SDK, you can build applications on top of Amazon S3, Amazon EC2, Amazon DynamoDB, and more.
-
Single-service actions - Code examples that show you how to call individual service functions.
-
Single-service scenarios - Code examples that show you how to accomplish a specific task by calling multiple functions within the same service.
-
Cross-service examples - Sample applications that work across multiple AWS services.
Single-service actions and scenarios are organized by AWS service in the dotnetv3 folder. A README in each folder lists and describes how to run the examples.
Cross-service examples are located in the cross-services folder. A README in each folder describes how to run the example.
- Running this code might result in charges to your AWS account.
- Running the tests might result in charges to your AWS account.
- We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see Grant least privilege.
- This code is not tested in every AWS Region. For more information, see AWS Regional Services.
To build and run the code examples for the AWS SDK for .NET, you need the following:
-
The appropriate .NET SDK for .NET. Most examples use .NET 6, but some require .NET 5.
-
The AWS SDK for .NET. For more information, see the AWS SDK for .NET Developer Guide.
-
AWS credentials, either configured in a local AWS credentials file, or by setting the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables. For more information, see the authentication topics in the AWS SDK for .NET Developer Guide and the AWS Tools and SDKs Shared Configuration and Credentials Reference Guide.
To build and run a code example, follow the instructions in the README file for the service. In general, follow these steps:
- Navigate to the directory containing a .sln file.
- Build the solution using
dotnet build SOLUTION.sln
, where SOLUTION.sln is the name of the .sln file. - Navigate to the directory containing the code example and a .csproj file.
- Run the project using the
dotnet run
command.
We rely on dotnet-format to keep this code consistently formatted and styled. To contribute .NET code to this project, please refer to the following installation and usage steps.
We run dotnet-format using a custom configuration file against any changed file or directory. See the .NET Github Action workflow for details.
To invoke dotnet-format yourself, first install it with
dotnet tool install -g dotnet-format`.
Next, run the dotnet-format command in the directory of your solution or project:
dotnet format
Most service folders also include a test project and either integration tests, unit tests, or both. To run all the tests, navigate to the folder that contains the test project and then issue the following command:
dotnet test
If you want more information, run:
dotnet test -l "console;verbosity=detailed"
To specify either unit or integration tests only, use the following category filters with the desired verbosity:
dotnet test --filter Category=Unit -l "console;verbosity=detailed"
or
dotnet test --filter Category=Integration -l "console;verbosity=detailed"
This example code will soon be available in a container image hosted on Amazon Elastic Container Registry (ECR). This image will be pre-loaded with all .NET examples ready to build and run, so that you can explore these examples in an isolated environment.
- Install and run Docker on your machine.
- Navigate to the same directory as this README.
- Run
docker build -t <image_name> .
whereimage_name
is a name you provide for the image.
- Run
docker run -it -v <your_credentials_folder_path>/.aws/credentials:/root/.aws/credentials <image_name>
.-it
launches an interactive terminal.-v <your_cred...
is optional but recommended. It will mount your local credentials file to the container. - The terminal initiates a bash instance at the root of the container. Run
cd dotnetv3
. Then, you can run examples and tests by navigating to a service folder and following the README instructions there. For example, navigate to thedotnetv3/Route53/Scenarios
folder and execute thedotnet run
command to build and run an interactive scenario for Amazon Route 53.
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0