-
Notifications
You must be signed in to change notification settings - Fork 862
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
IsUserCryptoAvailable check slows down Lambda cold start and takes large part of the initialization of Config and ServiceClients #2537
Comments
@unchartedxx Good morning. I understand that the call to Thanks, |
@ashishdhingra thanks for the quick answer. I did some more tests hoping that it would clarify your doubts. I redid the test using the official AWS .NET lambda blueprints from here. I only added code to measure the impact of the I tested with .NET 6 using the runtime provided by the lambda service and also using the custom runtime using .NET 7 in AOT mode. The Lambda function was assigned with 256MB. Each situation was tested three times, each time forcing a cold start. All times in milliseconds. .NET 6 Only Client Initialization
.NET 6 Calling
.NET 7 AOT Only Client Initialization
.NET 7 AOT Calling
It is possible to see that if the Here the whole code I used for reference:
|
We just released an update (included in It does require targeting .NET 8 (or greater), but should help with the latency you were seeing. |
Comments on closed issues are hard for our team to see. |
Describe the bug
I'm using the AWS SDK to build a lambda function on .NET 7 in AOT mode. I noticed that during Dependency Injection the creation of AmazonLambdaConfig and AmazonLambdaClient objects was taking the majority of the time of the whole startup. I enabled the SDK logs (AWSConfigs.LoggingConfig.LogTo = LoggingOptions.Console;) and I noticed the following messages (emphasis on the second line):
That UserCrypto message is generated at IsUserCryptAvailable.
That method is called whenever downstream it needs to try to get profile information if possible in CredentialProfileStoreChain. The get profile method is called indirectly whenever it needs to find credentials or profile configuration such as this or even this.
I want to note that all of this is not specific to the AmazonLambdaClient so I suppose it would affect all AWSSDK service clients.
Normally creating the Config and the Client without doing anything spacial takes between 150 and 200ms. If I call UserCrypto.IsUserCryptoAvailable in my code it takes around ~140 ms. If I create Config and Client after that it takes a few tens of milliseconds to do the initialisation. Therefore I can conclude that the single call to UserCrypto is taking the majority of the time even considering all the time to obtain credentials following the chain of folders, envvars,...
The test was done on .NET 7 and AOT. I can only assume it would take much more on earlier versions and/or non-AOT mode. The lambda was set with 256MB.
Expected Behavior
The AWS SDK notices it is running on a non-Windows enviroment and just return false to "UserCrypto.IsUserCryptAvailable" doesn't even try to call UserCrypto API and fail when the dll are not there.
Current Behavior
"UserCrypto.IsUserCryptAvailable" calls "Decrypt" that calls "CryptProtectData" that is a Windows only API but it tries anyway for the presence of the Crypt32.dll.so file and then fails.
Reproduction Steps
AWSConfigs.LoggingConfig.LogTo = LoggingOptions.Console;
var clientConfig = new AmazonLambdaConfig();
var client = new AmazonLambdaClient(clientConfig);
Possible Solution
Checks for current operating system in "UserCrypto.IsUserCryptAvailable". Return false if not Windows.
Additional Information/Context
The only workaround ATM to avoid any possible call to IsUserCryptoAvailable is to set a lot of stuff ahead of time before creating the ClientConfig and the ServiceConfig:
AWS .NET SDK and/or Package version used
AWSSDK.Lambda 3.7.104.7
Targeted .NET Platform
.NET 7 (AOT)
Operating System and version
Lambda (Amazon Linux 2)
The text was updated successfully, but these errors were encountered: