如何将对象从Xamarin表单保存到AWS DynamoDB
我正在创建一个移动应用程序,允许用户使用AWS Cognito通过facebook登录。处理类似以下内容的代码如何将对象从Xamarin表单保存到AWS DynamoDB,xamarin,amazon-dynamodb,amazon-cognito,Xamarin,Amazon Dynamodb,Amazon Cognito,我正在创建一个移动应用程序,允许用户使用AWS Cognito通过facebook登录。处理类似以下内容的代码 public async Task FacebookCongitoLogin(FacebookProfile profile) { config = new AmazonCognitoSyncConfig { RegionEndpoint = RegionEndpoint.USEast1 }; creds = new CognitoAWSCredent
public async Task FacebookCongitoLogin(FacebookProfile profile)
{
config = new AmazonCognitoSyncConfig { RegionEndpoint = RegionEndpoint.USEast1 };
creds = new CognitoAWSCredentials("ARN_ID_STUFF", RegionEndpoint.USEast1);
creds.AddLogin("graph.facebook.com", MySettings.FBToken);
syncManager = new CognitoSyncManager(creds, config);
await creds.GetCredentialsAsync();
Content = null;
saveProfileInfo(profile);
}
private void saveProfileInfo(FacebookProfile profile)
{
Dataset profileData = syncManager.OpenOrCreateDataset("fb_profile");
profileData.OnSyncSuccess += SyncSuccessCallback;
profileData.OnSyncFailure += SyncFailureCallback;
profileData.Put("fb_profile",JsonConvert.SerializeObject(profile));
profileData.SynchronizeAsync();
}
在我让用户登录之后,我正试图将一个对象安全地保存到我新创建的DynamoDB表中,就像这样
using System;
using System.Threading.Tasks;
using Amazon;
using Amazon.CognitoIdentity;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DataModel;
namespace TechPact
{
public class CreateInviteAction
{
private CognitoAWSCredentials creds;
public CreateInviteAction()
{
var token = TechPactSettings.FBToken;
creds = new CognitoAWSCredentials("ARN_ID_KEY", RegionEndpoint.USEast1);
creds.AddLogin("graph.facebook.com", token);
creds.GetCachedCredentials();
}
public async Task execute(Invite invite)
{
var client = new AmazonDynamoDBClient(creds, RegionEndpoint.USEast1);
var context = new DynamoDBContext(client);
await context.SaveAsync(invite);
}
}
}
当上面的操作运行时,我得到一个AmazondynamodException用户:arn:aws:sts::12323424:assumedrole/inviteapp\u auth\u MOBILEHUB\u 123234245/CognitoIdentityCredentials未被授权在资源上执行:dynamodb:可描述:arn:aws:dynamodb:us-ease-1:1232314234:table/Invite
下面是我为用户池创建的自定义角色police
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:*"
],
"Resource": [
"arn:aws:dynamodb:us-east-1:12312312312:table/invite-mobilehub-234234234-Invite"
],
"Condition": {
"ForAllValues:StringEquals": {
"dynamodb:LeadingKeys": [
"${graph.facebook.com:id}"
]
}
}
}
]
}
您能否共享链接到此池的IAM角色?它们会在创建身份池时自动创建。通过该消息,您似乎需要将dynamodb:descripbetable添加到您的身份验证角色中。@JeffBailey在上面添加了我从Congnito角色生成器生成的角色。我确实为这篇文章更改了一些dynamodb arn的数字,但是其他的都是我在用户池角色policy中所做的,这个角色中的资源看起来很混乱。它应该是“arn:aws:dynamodb:::table/,根据您的错误消息,这意味着它的表名是错误的。您是否认为它应该是类似于arn:aws:dynamodb:us-east-1:12312:table/invited的内容?是的,请试一试。作为对未来发现这个问题的人的补充,一位前Cognito团队成员写了一篇关于这个主题的优秀博客: