aws / aws/aws-sdk-net

RegisterSigV4aProvider doesn't work with AOT

Open
#3,969 4 comments 0 reactions 1 assignee Claimed by @dscpinheiro View on GitHub
aot bug credentials p2
Dominant language
C#
Stars
140
Forks
891
Avg merge
21h 51m
Merged PRs (30d)
10

Description

### Describe the bug

I have a simple AOT application which sending an event to EventBridge using a global endpoint.

If I run this application, I get an error at runtime:
> Unhandled Exception: Amazon.RuntimeDependencies.MissingRuntimeDependencyException: Operation failed because of a missing runtime dependency. In Native AOT builds runtime dependencies can not be dynamically loaded from assembles. Instead the runtime dependency needs to be explicitly registered. To complete this operation register an instance of Amazon.Extensions.CrtIntegration.CrtAWS4aSigner from package AWSSDK.Extensions.CrtIntegration using the operation Amazon.RuntimeDependencies.GlobalRuntimeDependencyRegistry.Instance.RegisterSigV4aProvider.

If I add what I believe to be the required code (see repro below) I get another error:
> Unhandled Exception: System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
---> System.NullReferenceException: Object reference not set to an instance of an object.
at Aws.Crt.NativeAPI.BindImpl[D](String) + 0x65
at Aws.Crt.Auth.AwsSigner.API..cctor() + 0x19

Could be I'm doing something wrong, but the registration matches what the error tells me to do.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Expected Behavior

RegisterSigV4aProvider should allow Event Bridge global endpoints to be used.

### Current Behavior

RegisterSigV4aProvider results in another error.

### Reproduction Steps

```xml


Exe
net8.0
enable
enable
true
true




```
```c#
using Amazon.EventBridge;
using Amazon.EventBridge.Model;
using Amazon.Extensions.CrtIntegration;
using Amazon.RuntimeDependencies;

GlobalRuntimeDependencyRegistry.Instance.RegisterSigV4aProvider(context =>
{
return new CrtAWS4aSigner(context.SigV4aCrtSignerContextData.SignPayload);
});

var client = new AmazonEventBridgeClient();

var request = new PutEventsRequest
{
EndpointId = "my-endpoint-id",
Entries =
[
new PutEventsRequestEntry
{
Detail = "TEST",
DetailType = "MyDetailType",
Source = "MySource",
EventBusName = "default"
}
]
};

var response = await client.PutEventsAsync(request);

Console.WriteLine(response.HttpStatusCode);
```
If this is published and ran, the error will occur.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### AWS .NET SDK and/or Package version used

AWSSDK.EventBridge 4.0.3.5
AWSSDK.Extensions.CrtIntegration 4.0.0

### Targeted .NET Platform

.NET 8

### Operating System and version

Windows 10 / Linux

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.