Forum Libraries, Components, and Plugins

AWS DynamoDB

Hi

I have created an account on AWS, as well as a DynamoDB. I have also set the permissions. Basically, I have followed this article to a T docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/getting-started-store-retrieve-data.html

But when I try to save a value into the table I get this error:

"The type initializer for 'Amazon.Util.CryptoUtilFactory' threw an exception."

As you can see the error itself is very vague.

Here is my code:

var Cred = new CognitoAWSCredentials("MY_IDENTITY_ID", RegionEndpoint.USWest2);


var dynamoClient = new AmazonDynamoDBClient(Cred, RegionEndpoint.USWest2);
var dynamoContext = new DynamoDBContext(dynamoClient);


Nearby_Favorites newFav = new Nearby_Favorites()
{
Id = 1,
PlaceName = Details.result.name,
PlaceId = Place.place_id,
Latitude = Place.geometry.location.lat.ToString(),
Longitude = Place.geometry.location.lng.ToString(),
Vicinity = Place.vicinity
};

await dynamoContext.SaveAsync(newFav);

Any help on this would be greatly appreciated.

Thank you.

Tagged:

Answers

  • batmacibatmaci DEMember ✭✭✭✭✭

    did you find any solution for this?

  • No, I have not. I ditched AWS momentarily. Working on something else. But will get back to it.

  • batmacibatmaci DEMember ✭✭✭✭✭
    edited December 2016

    your error is really strange. after I wrote you, I achieved successful inserts and updates. my code looks like yours. your problem might be on the server side. maybe you want to create your DB again. But in general, I didnt like aws, when you have error or dont understand something, you cant get enough help, you have to pay for support starting from 29$ which many devs will not be willing to pay. their .net/xamarin sdk is also quite incomplete and i dont think that they care about it.

  • FabricioBertaniFabricioBertani USMember ✭✭✭
    edited March 2017

    Hi, i know is a bit late, but here is my code that work fine (actually i'm using the aws api gateway and working with json)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Amazon;
    using Amazon.DynamoDBv2;
    using Amazon.DynamoDBv2.DocumentModel;
    using Amazon.DynamoDBv2.DataModel;
    using Amazon.DynamoDBv2.Model;
    using Amazon.CognitoIdentity;
    using Xamarin.Forms;
    
    namespace DynamoDbPutItemTest
    {
        public partial class DynamoDbPutItemTest : ContentPage
        {
            CognitoAWSCredentials credentials = new CognitoAWSCredentials(
                "MY_IDENTITY_ID",
                RegionEndpoint.USEast1
            );
    
            public DynamoDbPutItemTest()
            {
                InitializeComponent();
    
                loadingLay.IsEnabled = false; // loadingLay is a xaml StackLayout inside a BoxView that display an ActivityIndicator
                loadingLay.IsVisible = false;
    
                signUpButton.Clicked += OnSignUpButtonClicked;
            }
    
            public async void OnSignUpButtonClicked(object sender, EventArgs e)
            {
                loadingLay.IsVisible = true;
                loadingLay.IsEnabled = true;
    
                var user = new Users()
                {
                    User = usernameEntry.Text,
                    Password = passwordEntry.Text,
                    Email = emailEntry.Text,
                    Name = nameEntry.Text,
                    LastName = lastnameEntry.Text,
                    BirthDay = datePicker.Date.ToString()
                };
    
                var client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast1);
                DynamoDBContext context = new DynamoDBContext(client);
    
                Users userRegistration = new Users()
                {
                    User = user.User,
                    Password = user.Password,
                    Email = user.Email,
                    Name = user.Name,
                    LastName = user.LastName,
                    BirthDay = user.BirthDay
                };            
    
                var signUpSucceeded = AreDetailsValid(user);
                if (signUpSucceeded)
                {
                    await context.SaveAsync(userRegistration); // -> this save data to DynamoDb Table
    
                    var rootPage = Navigation.NavigationStack.FirstOrDefault();
                    if (rootPage != null)
                    {
                        loadingLay.IsEnabled = false;
                        loadingLay.IsVisible = false;
                        var action = await DisplayActionSheet("Success", null, "OK", "User registered successfully!");
                        switch (action)
                        {
                            case "OK":
                                App.IsUserLoggedIn = true;
                                Navigation.InsertPageBefore(new LoginPage(), Navigation.NavigationStack.First());
                                await Navigation.PopToRootAsync();
                                break;
                        }
                    }                
                }
                else
                {
                    loadingLay.IsEnabled = false;
                    loadingLay.IsVisible = false;
    
                    var action = await DisplayActionSheet("There was a mistake", null, "OK", "Please verify the data.");
                }
            }
    
            bool AreDetailsValid(Users user)
            {
                return (!string.IsNullOrEmpty(user.User) &&
                    !string.IsNullOrEmpty(user.Password) &&
                    !string.IsNullOrEmpty(user.Email) && user.Email.Contains("@") &&
                    !string.IsNullOrEmpty(user.Name) &&
                    !string.IsNullOrEmpty(user.LastName) &&
                    !string.IsNullOrEmpty(user.BirthDay));
            }
        }
    }
    

    Hope this work for you :wink:

    edit: and i forgot tha you need to make an class for your table, like this:

    using Amazon.DynamoDBv2.DataModel;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection.Emit;
    using System.Text;
    
    namespace DynamoDbPutItemTest
    {
        [DynamoDBTable("UsersTest")]
        public class Users
        {
            [DynamoDBHashKey]
            public string User { get; set; }
    
            [DynamoDBRangeKey]
            public string Password { get; set; }
    
            [DynamoDBProperty]
            public string Email { get; set; }
    
            [DynamoDBProperty]
            public string Name { get; set; }
    
            [DynamoDBProperty]
            public string LastName { get; set; }
    
            [DynamoDBProperty]
            public string BirthDay { get; set; }
        }
    }
    
  • ali_jaxxadali_jaxxad Member ✭✭

    I followed the instructions from AWS, to upload the DynamoDB table. Below is my code which should be working but it is not. There are no errors but the table is not getting updated.

    using Android.App;
    using Android.Widget;
    using Android.OS;
    using Amazon;
    using Amazon.DynamoDBv2;
    using Amazon.DynamoDBv2.DocumentModel;
    using Amazon.DynamoDBv2.DataModel;
    using Amazon.DynamoDBv2.Model;
    using Amazon.CognitoIdentity;

    namespace AWS_TESTING
    {

    [Activity(Label = "AWS_TESTING", MainLauncher = true, Icon = "@mipmap/icon")]
    public class MainActivity : Activity
    {
        CognitoAWSCredentials credentials = new CognitoAWSCredentials(
           "us-east-1:53d834ae-2af4-46e7-a6b2-31f12a30b2f0",
           RegionEndpoint.USEast1
         );
    
        public class Book
        {
            [DynamoDBHashKey]    // Hash key.
            public int Id { get; set; }
            public string Title { get; set; }
            public string ISBN { get; set; }
            public int Price { get; set; }
            public string PageCount { get; set; }
            public string Author { get; set; }
        }
    
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);
    
            Button ButtonSync = FindViewById<Button>(Resource.Id.myButton);
            TextView InfoText = FindViewById<TextView>(Resource.Id.textView1);
    
    
    
            var client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast1);
            DynamoDBContext context = new DynamoDBContext(client);
    
            ButtonSync.Click += delegate 
            {
                Book songOfIceAndFire = new Book()
                {
                    Id = 1,
                    Title = "Game Of Thrones",
                    ISBN = "978-0553593716",
                    Price = 4,
                    PageCount = "819",
                    Author = "GRRM"
                };
    
                context.SaveAsync(songOfIceAndFire);
    
                InfoText.Text = "UPLOADED";
            };
        }
    }
    

    }

  • ali_jaxxadali_jaxxad Member ✭✭

    Hi, I am trying to upload data on DynamoDB table. Below is my code. It is running fine without any errors but somehow the table is not getting updated. I followed the AWS tutorial in doing so.

    using Android.App;
    using Android.Widget;
    using Android.OS;
    using Amazon;
    using Amazon.DynamoDBv2;
    using Amazon.DynamoDBv2.DocumentModel;
    using Amazon.DynamoDBv2.DataModel;
    using Amazon.DynamoDBv2.Model;
    using Amazon.CognitoIdentity;
    
    namespace AWS_TESTING
    {
    
        [Activity(Label = "AWS_TESTING", MainLauncher = true, Icon = "@mipmap/icon")]
        public class MainActivity : Activity
        {
            CognitoAWSCredentials credentials = new CognitoAWSCredentials(
               "us-east-1:53d834ae-2af4-46e7-a6b2-31f12a30b2f0",
               RegionEndpoint.USEast1
             );
    
            public class Book
            {
                [DynamoDBHashKey]    // Hash key.
                public int Id { get; set; }
                public string Title { get; set; }
                public string ISBN { get; set; }
                public int Price { get; set; }
                public string PageCount { get; set; }
                public string Author { get; set; }
            }
    
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
                SetContentView(Resource.Layout.Main);
    
                Button ButtonSync = FindViewById<Button>(Resource.Id.myButton);
                TextView InfoText = FindViewById<TextView>(Resource.Id.textView1);
    
    
    
                var client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast1);
                DynamoDBContext context = new DynamoDBContext(client);
    
                ButtonSync.Click += delegate 
                {
                    Book songOfIceAndFire = new Book()
                    {
                        Id = 1,
                        Title = "Game Of Thrones",
                        ISBN = "978-0553593716",
                        Price = 4,
                        PageCount = "819",
                        Author = "GRRM"
                    };
    
                    context.SaveAsync(songOfIceAndFire);
    
                    InfoText.Text = "UPLOADED";
                };
            }
        }
    }
    
Sign In or Register to comment.