예제 #1
0
        private static IAmazonDynamoDB CreateClient(
            ICredentialsProvider credentialsProvider,
            IDynamoDbOptions <T> options
            )
        {
            AWSCredentials credentials = credentialsProvider.GetCredentials(options.CredentialsProfile);

            if (!string.IsNullOrWhiteSpace(options.Role))
            {
                credentials = credentialsProvider.AssumeRole(
                    credentials,
                    options.Role
                    );
            }

            if (!string.IsNullOrWhiteSpace(options.RegionEndpoint))
            {
                AmazonDynamoDBConfig config = new AmazonDynamoDBConfig {
                    RegionEndpoint = RegionEndpoint.GetBySystemName(options.RegionEndpoint)
                };
                return(new AmazonDynamoDBClient(credentials, config));
            }

            return(new AmazonDynamoDBClient(credentials));
        }
예제 #2
0
        public DynamoDbContext(
            ICredentialsProvider credentialsProvider,
            IDynamoDbOptions <T> options
            )
        {
            if (options is null)
            {
                throw new ArgumentException($"{nameof( options )} must not be null.", nameof(options));
            }

            if (credentialsProvider is null)
            {
                throw new ArgumentException($"{nameof( credentialsProvider )} must not be null.", nameof(credentialsProvider));
            }

            Client  = CreateClient(credentialsProvider, options);
            Context = new DynamoDBContext(Client);
        }