You can set up the AWS Mobile SDK for .NET and MAUI and start building a new project or you can integrate the SDK with an existing project.
Prerequisites
Before you can use the AWS Mobile SDK for .NET and MAUI, you must do the following:
- Create an An AWS Account.
- Install the .NET MAUI workload.
After you complete the prerequisites:
- Obtain AWS credentials by using Amazon Cognito.
- Set the required permissions for each AWS service that you will use in your application.
- Create a new project in your IDE.
- Install the AWS Mobile SDK for .NET and MAUI.
- Configure the AWS Mobile SDK for .NET and MAUI.
If you would like some assistance with .NET MAUI | Azure | Azure DevOps Services | Blazor Development then please get in touch, we would be glad to help.
Step 1: Obtain AWS Credentials
To make calls to AWS in your application, you must first obtain AWS credentials. You do this by using Amazon Cognito, an AWS service that allows your application to access the services in the SDK without having to embed your private AWS credentials in the application.
To get started with Amazon Cognito, you need to create an identity pool. An identity pool is a store of information that is specific to your account and is identified by a unique identity pool ID that looks like the following.:
"us-east-1:00000000-0000-0000-0000-000000000000"
- Log in to the Amazon Cognito Console , choose Manage Federated Identities, and then choose Create new identity pool.
- Enter a name for your identity pool and select the checkbox to enable access to unauthenticated identities. Choose Create Pool to create your identity pool.
- Choose Allow to create the two default roles associated with your identity pool, one for unauthenticated users and one for authenticated users. These default roles provide your identity pool access to Amazon Cognito Sync and Amazon Mobile Analytics.
Typically, you will only use one identity pool per application.
After you create your identity pool, you obtain AWS credentials by creating a CognitoAWSCredentials
object (passing it your identity pool ID) and then passing it to the constructor of an AWS client as follows.:
CognitoAWSCredentials credentials = new CognitoAWSCredentials ( "us-east-1:00000000-0000-0000-0000-000000000000", // Your identity pool ID RegionEndpoint.USEast1 // Region); // Example for |MA|analyticsManager = MobileAnalyticsManager.GetOrCreateInstance( credentials, RegionEndpoint.USEast1, // Region APP_ID // app id);
Step 2: Set Permissions
You need to set permissions for every AWS service that you want to use in your application. First, you need to understand how AWS views the users of your application.
When someone uses your application and makes calls to AWS, AWS assigns that user an identity. The identity pool that you created in Step 1 is where AWS stores these identities. There are two types of identities: authenticated and unauthenticated. Authenticated identities belong to users who are authenticated by a public login provider (e.g., Facebook, Amazon, Google). Unauthenticated identities belong to guest users.
Every identity is associated with an AWS Identity and Access Management role. In Step 1, you created two IAM roles, one for authenticated users and one for unauthenticated users. Every IAM role has one or more policies attached to it that specify which AWS services the identities assigned to that role can access. For example, the following sample policy grants access to an Amazon S3 bucket.:
{ "Statement": [ { "Action": [ "s3:AbortMultipartUpload", "s3:DeleteObject", "s3:GetObject", "s3:PutObject" ], "Effect": "Allow", "Resource": "arn:aws:s3:::MYBUCKETNAME/*", "Principal": "*" } ] }
To set permissions for the AWS services that you want to use in your application, modify the policy attached to the roles.
- Go to the IAM Console and choose Roles. Type your identity pool name into the search box. Choose the IAM role that you want to configure. If your application allows both authenticated and unauthenticated users, you need to grant permissions for both roles.
- Click Attach Policy, select the policy you want, and then click Attach Policy. The default policies for the IAM roles that you created provide access to Amazon Cognito Sync and Mobile Analytics.
For more information about creating policies or to choose from a list of existing policies, see IAM Policies.
Step 3: Create a New Project
Windows
You can use Visual Studio to develop your application.
OS X
You can use Visual Studio to develop your applications. iOS development using Xamarin requires access to a Mac to run your app. For more information, see Installing Xamarin.iOS on Windows.
Note
The cross-platform commercial IDE Rider from JetBrains includes Xamarin support on both Windows and Mac platforms.
Step 4: Install the AWS Mobile SDK for .NET and Xamarin
Windows
Option 1: Install by Using the Package Manager Console
The AWS Mobile SDK for .NET and Xamarin consists a set of .NET assemblies. To install the AWS Mobile SDK for .NET and Xamarin, run the install-package command for each package in the Package Manager console. For example, to install Cognito Identity, run the following.:
Install-Package AWSSDK.CognitoIdentity
The AWS Core Runtime and Amazon Cognito Identity packages are required for all projects. The following is a full list of package names for each service.
ServicePackage name
AWS Core Runtime
AWSSDK.Core
Amazon Cognito Sync
AWSSDK.CognitoSync
Amazon Cognito Identity
AWSSDK.CognitoIdentity
Amazon DynamoDB
AWSSDK.DynamoDBv2
Amazon Mobile Analytics
AWSSDK.MobileAnalytics
Amazon S3
AWSSDK.S3
Amazon SNS
AWSSDK.SimpleNotificationService
To include a prerelease package, include the -Pre
command line argument while installing the package as follows.:
Install-Package AWSSDK.CognitoSync -Pre
You can find a complete list of AWS service packages at AWS SDK packages on NuGet or at the AWS SDK for .NET GitHub Repository.
Option 2: Install by Using Your IDE
In Visual Studio
- Right-click the project, and then click Manage NuGet Packages.
- Search for the package name that you want to add to your project. To include the prelease NuGet packages, choose Include Prelease. You can find a complete list of AWS service packages at AWS SDK packages on NuGet.
- Choose the package, and then choose Install.
Mac (OS X)
In Visual Studio
- Right-click the packages folder, and then choose Add Packages.
- Search for the package name that you want to add to your project. To include the prelease NuGet packages, choose Show pre-release packages. You can find a complete list of AWS service packages at AWS SDK packages on NuGet.
- Select the checkbox next to the package you want, and then choose Add Package.
Important
If you are developing using a Portable Class Library, you must also add the AWSSDK.Core NuGet package to all projects deriving from the Portable Class Library.
Step 5: Configure the AWS Mobile SDK for .NET and Xamarin
Set Logging
You set logging settings by using the Amazon.AWSConfigs
class and the Amazon.Util.LoggingConfig
class. You can find these in the AWSSdk.Core
assembly, available through the Nuget Package Manager in Visual Studio. You can place the logging settings code in the OnCreate
method in the MainActivity.cs
file for Android apps or the AppDelegate.cs
file for iOS apps. You should also add using Amazon
and using Amazon.Util
statements to the .cs files.
Configure logging settings as follows.:
var loggingConfig = AWSConfigs.LoggingConfig; loggingConfig.LogMetrics = true; loggingConfig.LogResponses = ResponseLoggingOption.Always; loggingConfig.LogMetricsFormat = LogMetricsFormatOption.JSON; loggingConfig.LogTo = LoggingOptions.SystemDiagnostics;
When you log to SystemDiagnostics, the framework internally prints the output to the System.Console. If you want to log HTTP responses, set the LogResponses
flag. The values can be Always, Never, or OnError.
You can also log performance metrics for HTTP requests by using the LogMetrics
property. The log format can be specified by using LogMetricsFormat
property. Valid values are JSON or standard.
Set the Region Endpoint
Configure the default region for all service clients as follows.:
AWSConfigs.AWSRegion="us-east-1";
This sets the default region for all the service clients in the SDK. You can override this setting by explicitly specifying the region at the time of creating an instance of the service client, as follows.:
IAmazonS3 s3Client = new AmazonS3Client(credentials,RegionEndpoint.USEast1);
Configure the HTTP Proxy Settings
If your network is behind a proxy, you can configure the proxy settings for the HTTP requests as follows.
var proxyConfig = AWSConfigs.ProxyConfig; proxyConfig.Host = "localhost"; proxyConfig.Port = 80; proxyConfig.Username = "<username>"; proxyConfig.Password = "<password>";
Correct for Clock Skew
This property determines if the SDK should correct for client clock skew by determining the correct server time and reissuing the request with the correct time.
AWSConfigs.CorrectForClockSkew = true;
This field is set if a service call resulted in an exception and the SDK has determined that there is a difference between local and server times.
var offset = AWSConfigs.ClockOffset;
To learn more about clock skew, see Clock-skew Correction on the AWS Blog.
At Assemblysoft we specialise in Custom Software Development tailored to your requirements. We can onboard and add value to your business rapidly. We are an experienced Full-stack development team able to provide specific technical expertise or manage your project requirements end to end. We specialise in the Microsoft cloud and .NET Solutions and Services. Our developers are Microsoft Certified. We have real-world experience developing .NET applications and Azure Services for a large array of business domains. If you would like some assistance with Azure | Azure DevOps Services | Blazor Development | .NET MAUI Development or in need of custom software development, from an experienced development team in the United Kingdom, then please get in touch, we would love to add immediate value to your business.
Assemblysoft - Your Safe Pair of Hands