-
Notifications
You must be signed in to change notification settings - Fork 859
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internal Server Error when trying to access Multi Region Access Point with Assuming Role. #3004
Comments
Hi @kpok, Good afternoon. I'm unsure how you have configured Lambda and roles, here are the steps that I used to reproduce the issue:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Principal": {
"AWS": [
"arn:aws:iam::<<account-id>>:role/testmraplambda"
]
},
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3::<<account-id>>:accesspoint/<<mrap-alias.mrap>>/object/*"
]
}
]
}
using Amazon;
using Amazon.Lambda.Core;
using Amazon.S3;
using Amazon.S3.Model;
using Amazon.SecurityToken;
using Amazon.SecurityToken.Model;
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace TestMRAPLambda;
public class Function
{
public void FunctionHandler(ILambdaContext context)
{
AWSConfigs.LoggingConfig.LogTo = LoggingOptions.Console;
AWSConfigs.LoggingConfig.LogResponses = ResponseLoggingOption.Always;
AWSConfigs.LoggingConfig.LogMetrics = true;
var s3Endpoint = "arn:aws:s3::<<account-id>>:accesspoint/<<mrapalias.mrap>>";
Console.WriteLine($"S3Endpoint: {s3Endpoint}");
var s3Client = new AmazonS3Client();
var stream = GenerateStreamFromString("test1");
var putObjectRequest = new PutObjectRequest()
{
BucketName = s3Endpoint,
Key = "testFromLambda.txt",
InputStream = stream
};
var result = s3Client.PutObjectAsync(putObjectRequest).Result;
Console.WriteLine(result);
Console.WriteLine(result.HttpStatusCode);
}
public static Stream GenerateStreamFromString(string s)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.Position = 0;
return stream;
}
} Also ensured to add reference to <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<!-- Generate ready to run images during publishing to improve cold start time. -->
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.1" />
<PackageReference Include="AWSSDK.Extensions.CrtIntegration" Version="3.7.1.8" />
<PackageReference Include="AWSSDK.S3" Version="3.7.200.1" />
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.200.1" />
</ItemGroup>
</Project> Reference to
I'm unsure why you need to assume a role when you would attach role to Lambda during deployment. Please let me know if I'm missing something from the reproduction steps. Are you using a different role attached to Lambda function? NOTE: I have hard-coded ARNs for reproduction. This should be avoided in production. Also, we should dispose of Amazon S3 client after use (mat be wrap in Thanks, |
Hi @ashishdhingra For the bug reproduction I am trying to assume role from another lambda role on the same AWS account but the same error occurs also when I try to do with different accounts. Regards, |
One common "sharp edge" with MRAPs and assumed roles is mentioned on https://docs.aws.amazon.com/AmazonS3/latest/userguide/MultiRegionAccessPointRestrictions.html
V3 of the .NET SDK still defaults to the global STS endpoint. Can you check which endpoint the STS request is going to? And if it's still the global endpoint, configure it to go to a regional endpoint instead?
|
Hi @ashovlin I replaced below line: with lines: var config = new AmazonSecurityTokenServiceConfig() { StsRegionalEndpoints = StsRegionalEndpointsValue.Regional }; and the solution started to work. Thank you. |
Glad it worked! Yeah, the defaulting to |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
I am trying to implement lambda which will assume role and then will send a file to S3 bucket through Multi-region access point.
Lambda throws Internal Server Error exception -> See lambda details in reproduction Steps.
Expected Behavior
File should appear in S3 bucket under the Multi-Region Access Point.
Current Behavior
Below exception is thrown from line "var result = s3Client.PutObjectAsync(putObjectRequest).Result;":
System.AggregateException: One or more errors occurred. (We encountered an internal error. Please try again.) ---> Amazon.S3.AmazonS3Exception: We encountered an internal error. Please try again. ---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown. at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken) at Amazon.Runtime.Internal.HttpHandler
1.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.RedirectHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext) at Amazon.S3.Internal.AmazonS3ResponseHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext) --- End of inner exception stack trace --- at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream) at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionAsync(IExecutionContext executionContext, HttpErrorResponseException exception) at Amazon.Runtime.Internal.ExceptionHandler
1.HandleAsync(IExecutionContext executionContext, Exception exception) at Amazon.Runtime.Internal.ErrorHandler.ProcessExceptionAsync(IExecutionContext executionContext, Exception exception) at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext) at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task
1.get_Result() at IntegrationTests.TestFunction.FunctionHandler()Reproduction Steps
And with below code:
Possible Solution
No response
Additional Information/Context
The same situation occurs when I try to execute the Lambda Function Code from Console Application on Windows 10 machine while I have aws credentials configured which allows to assume role created in point 2 of reproduction steps.
Also worth to mention that below powershell + AWS CLI code works correctly. This code is doing a similar job as lambda while in this situation the operation ends successfully:
Version of AWS CLI:
aws-cli/2.12.7 Python/3.11.4 Windows/10 exe/AMD64 prompt/off
AWS .NET SDK and/or Package version used
Amazon.Lambda.Core 2.1.0
AWSSDK.Extensions.CrtIntegration 3.7.1.8
AWSSDK.S3 3.7.200
AWSSDK.SecurityToken 3.7.200
Targeted .NET Platform
.NET 6
Operating System and version
Lambda
The text was updated successfully, but these errors were encountered: