Hi all, I have one question and I can't find answer for it (SO, google, numerous tries my own code). How can I instantiate AmazonCognitoIdentityProviderClient?
I'm using .net core 2 and the code is really simple:
var credentials = new EnvironmentVariablesAWSCredentials();
CognitoProvider = new AmazonCognitoIdentityProviderClient(credentials, RegionEndpoint.EUCentral1);
But AmazonCognitoIdentityProviderClient throws exceptionSystem.IO.FileNotFoundException: 'Could not find file 'C:\Users\USER\.aws\credentials'.'
I know what it means, but why is it throwing that exception? I want to use environment credentials and they are all right (EnvironmentVariablesAWSCredentials doesnt complain and Environment.GetEnvironmentVariable on AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY returns correct values).
I can provide the file on my local environment but I can't do that on production. How am I suppose to pass credentials to cognito client? Am I missing something?
"AWS": {
"Region": ...,
"AccessKeyId": ...,
"SecretAccessKey":...
},
but I cannot create a s3 client
opConfig.QueryFilter =
new List<ScanCondition>
{
new ScanCondition("Status", ScanOperator.Equal, 10),
new ScanCondition("Status", ScanOperator.Equal, 4),
new ScanCondition("PlanType", ScanOperator.Equal, "SML"),
//new ScanCondition("NormalRoadConditions", ScanOperator.Equal, true)
};
List<string> partionKeys = new List<string>() { "52049E96-14FA-4960-B3CE-F7400C4AC6CD", "01F3DF08-4D0F-4E92-BBE3-8E46BA77E73B", "52117BC1-7256-4C36-868E-465DB2178286" };
if (!string.IsNullOrEmpty(TableName))
{
AWSConfigsDynamoDB.Context.TypeMappings[typeof(Plan)] = new Amazon.Util.TypeMapping(typeof(Plan), TableName);
}
var start = DateTime.Now;
int totalCount = 0;
var config = new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 };
var client = new AmazonDynamoDBClient(new StoredProfileAWSCredentials("sandbox"), RegionEndpoint.EUWest1);
DbContext = new DynamoDBContext(client, config);
var opConfig = new DynamoDBOperationConfig { IndexName = "OrganizationId-Created-index" };
opConfig.QueryFilter =
new List<ScanCondition>
{
new ScanCondition("Status", ScanOperator.Equal, 10),
new ScanCondition("Status", ScanOperator.Equal, 4),
new ScanCondition("PlanType", ScanOperator.Equal, "SML"),
//new ScanCondition("NormalRoadConditions", ScanOperator.Equal, true)
};
foreach (var partionKey in partionKeys)
{
var result = Program.DbContext.QueryAsync<Plan>(partionKey.ToLower(), opConfig);
while (!result.IsDone)
{
var plans = result.GetNextSetAsync().Result;
totalCount += plans.Count;
}
}
public async Task<string> FunctionHandler(S3Event evnt, ILambdaContext context)
{
var serviceCollection = new ServiceCollection();
ConfigureServices(serviceCollection);
// service provider
var serviceProvider = serviceCollection.BuildServiceProvider();
// entry to run app
var service = serviceProvider.GetService<ApplicationService>();
return await service.LocalFunctionHandler(evnt, context);
}
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<Logger>();
services.AddSingleton<IAmazonS3>(s3 => new AmazonS3Client(Amazon.RegionEndpoint.USEast1));
services.AddSingleton<IAmazonBatch>(batch => new AmazonBatchClient(Amazon.RegionEndpoint.USEast1));
services.AddTransient<ApplicationService>();
}
var token = await HttpContext.GetTokenAsync("access_token").ConfigureAwait(false);
var token1 = await HttpContext.GetTokenAsync("id_token").ConfigureAwait(false);
var accesToken = Request.Headers["Authorization"];
var refreshToken = await HttpContext.GetTokenAsync("refresh_token").ConfigureAwait(false);
AuthFlowResponse authResponse = await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest { Password = inPassword });
string idToken = authResponse.AuthenticationResult.IdToken;
@klaytaybai VersionId with whitespace is only our problem, I understand it.
The common problem is that this code crashes too:
var client = new AmazonS3Client(bucketRegion);
var request = new PutObjectRequest
{
Key = "test ",
BucketName = "bucket",
ContentBody = "test"
};
using (var response = await client.PutObjectAsync(request))
{
}
with SignatureDoesNotMatch.
http://blablabla/?key=test
, but signhttp://blablabla/?key=test%20
I'm receiving S3 errors when running a project in Visual Studio 2019, but which works just fine in VS 2017. The error happens when instantiating an AmazonS3Client :
AmazonS3Client s3Client = new AmazonS3Client(RegionEndpoint.USEast1);
and getting the error:
System.ArgumentException
HResult=0x80070057
Message=An item with the same key has already been added. Key: System.Collections.Generic.Dictionary
2[System.String,System.Collections.Generic.Dictionary2[System.String,System.Object]]
Source=System.Private.CoreLib
StackTrace:
at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException[T](T key)