Saturday 28 June 2014

Installing the AWS .NET SDK on Mono/Linux using NuGet

Following a previous post about compiling the AWS .NET SDK on Mono/Linux +David Fevre asked whether it was possible to use NuGet to install the SDK. It turns out that this is actually quite a bit simpler if you are running Mono 3.2+. Below are the steps required to get the AWS SDK working on Mono/Linux (Ubuntu 14.04)

1. Install mono and associated tools, mozroots downloads root certificates to enable SSL via mono:
sudo apt-get update
sudo apt-get install mono-complete git wget
mozroots --import --sync

2. Create a working directory and change to it:
mkdir mono-aws
cd mono-aws

3. Download the command line version of NuGet and verify that it is version 2.8+:
mono nuget.exe update -self

4. Install the AWSSDK via NuGet:
mono nuget.exe install AWSSDK

5. Create a symbolic link to the lib folder (note that the version number might be different from the example command):
ln -s AWSSDK. lib

6. Create a command line program to test with, for example in s3.cs:
using System;
using Amazon.S3;
using Amazon.S3.Model;

class Upload
  public static void Main(string[] args)
    // Create a client
    AmazonS3Client client = new AmazonS3Client(Amazon.RegionEndpoint.USWest2);

    // Create a PutObject request
    PutObjectRequest request = new PutObjectRequest
      BucketName = "SampleBucket",
      Key = "Item1",
      ContentBody = "This is sample content..."

    // Put object

7. Compile your program:
mcs s3.cs -r:./lib/AWSSDK.dll

8. Set the Mono path
export MONO_PATH=`pwd`/lib:.

9. Create an application configuration (must be named to match the compiled program) for example in s3.exe.config:
<?xml version="1.0"?>
    <add key="AWSAccessKey" value="AKXXXXXXXXXXXXXX"/>
    <add key="AWSSecretKey" value="XXXXXXXXXXXXXXXXXXXXXXXX"/>

10. Run your program and verify that the object is created in the bucket:
mono s3.exe