Search code examples
amazon-web-servicesrustaws-lambdaamazon-cognito

how to get authenticated user on API side


I am trying to use the amazon provided crates to get the authenticated user for the current request.

let region_provider = RegionProviderChain::default_provider()
    .or_else("us-east-1");
let config = aws_config::from_env().region(region_provider).load().await;
let cognito = aws_sdk_cognitoidentityprovider::Client::new(&config);

This code doesn't compile, saying that the aws_sdk_cognitoidentityprovider::Client constructor requires a type of SdkConfig. I have searched far and wide but couldn't find a way of constructing this SdkConfig type. Can someone help?

Exact error:

    mismatched types
expected reference `&aws_types::sdk_config::SdkConfig`
   found reference `&aws_config::Config`rustcE0308
main.rs(14, 19): arguments to this function are incorrect
client.rs(12040, 12): associated function defined here

Solution

  • Anyone wondering the way to instantiate the SdKConfig struct is: let sdkConfig = aws_types::sdk_config::SdkConfig::builder().build();