私はAWSの認証されていない/匿名のユーザーアクセスに自分の足元を浸しており、生成されたトークンをラムダ経由でCognitoから取得したいと考えていました。ラムダのAWS Cognitoを.NET用に使用
私は次のエラーでラムダで実行することができませんでした。
This functionality is not implemented in the portable version of this assembly
{
"errorType": "NotImplementedException",
"errorMessage": "This functionality is not implemented in the portable version of this assembly. You should reference the AWSSDK.Core NuGet package from your main application project in order to reference the platform-specific implementation.",
"stackTrace": [
"at Amazon.Util.Internal.PlatformServices.ApplicationSettings.GetValue(String key, ApplicationSettingsMode mode)",
"at Amazon.CognitoIdentity.CognitoAWSCredentials.GetCachedIdentityId()",
"at Amazon.CognitoIdentity.CognitoAWSCredentials..ctor(String accountId, String identityPoolId, String unAuthRoleArn, String authRoleArn, IAmazonCognitoIdentity cibClient, IAmazonSecurityTokenService stsClient)",
"at Amazon.CognitoIdentity.CognitoAWSCredentials..ctor(String accountId, String identityPoolId, String unAuthRoleArn, String authRoleArn, RegionEndpoint region)",
"at AwsDotnetCsharp.AuthHandler.Get(APIGatewayProxyRequest request, ILambdaContext context)",
"at lambda_method(Closure , Stream , Stream , ContextInfo)"
]
}
ラムダは、新しいC#のDOTNETコアバージョンではなく、JavaScriptがあります。私は
だからDOTNETコア(.NET標準1.6)writngの時にバージョン3.3.1.1であると(まだ)は互換性がありませんCognitoAWSCredentials
あるproject.jsonで(https://www.nuget.org/packages/AWSSDK.CognitoIdentity/)をAWSSDK.CoreとAWSSDK.SecurityTokenを参照していますそれがそうであると言うナゲットサイトで考えた。この作業を取得するためには何が必要です
マイラムダコードがされています...(右ではないかもしれないが、私はそれが前進するために実行するために取得することはできません)
public class AuthHandler
{
public APIGatewayProxyResponse Get(APIGatewayProxyRequest request, ILambdaContext context)
{
CognitoAWSCredentials credentials =
new CognitoAWSCredentials("us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", Amazon.RegionEndpoint.USEast1);
var identityPoolId = credentials.GetIdentityIdAsync();
AmazonCognitoIdentityClient cognitoClient = new AmazonCognitoIdentityClient(
credentials, // the anonymous credentials
Amazon.RegionEndpoint.USEast1 // the Amazon Cognito region
);
GetIdRequest idRequest = new GetIdRequest();
idRequest.AccountId = "############";
idRequest.IdentityPoolId = identityPoolId.Result;
var idResp = cognitoClient.GetIdAsync(idRequest);
var id = idResp.Result.IdentityId;
var response = new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.OK,
Body = $"{{ \"{id}\" }}",
Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } }
};
return response;
}
}
?