Unable to get IAM security credentials from EC2 Instance Metadata Service in Asp Net

Viewed 22

This is my service class

using Amazon;
using Amazon.CognitoIdentityProvider;
using Amazon.CognitoIdentityProvider.Model;
using backend.Models;
using Microsoft.AspNetCore.Mvc;

namespace backend.services
{
    public class RegisterUserService
    {
        private const string _clientId = "clientid";
        private readonly RegionEndpoint _region = RegionEndpoint.region;
        private readonly bookingengineContext bookingengineContext;
        private readonly string poolId = "poolid";

        public RegisterUserService(bookingengineContext bookingengineContext)
        {
            this.bookingengineContext = bookingengineContext;
        }

        public async Task Register(NewUser newUser)
        {
            var awsAccessKey = "myaccesskey";
            var awsSecretKey = "secretkey";
            var cognito = new AmazonCognitoIdentityProviderClient(_region);

            var request = new SignUpRequest
            {
        
                ClientId = _clientId,
                Password = newUser.Password,
                Username = newUser.Username
            };
            var emailAttribute = new AttributeType
            {
                Name = "email",
                Value = newUser.Email
            };
            request.UserAttributes.Add(emailAttribute);
            
            var response = await cognito.SignUpAsync(request);
            //bookingengineContext.
            
        }
    }
}

I want to register users and then store it in my database. So i want to add register user in backend. I am not able to understand what i did wrong.I have added my access key, secret key in my service for now . Later plan to shift it to appsetting.json.

0 Answers
Related