Ejemplo n.º 1
0
        protected BaseRepository()
        {
            _region    = RegionEndpoint.GetBySystemName(Environment.GetEnvironmentVariable("region"));
            _accessKey = Environment.GetEnvironmentVariable("accessKey");
            _secretKey = Environment.GetEnvironmentVariable("secretKey");

            AWS.LoadAWSBasicCredentials(_region, _accessKey, _secretKey);
        }
Ejemplo n.º 2
0
        public SettingFunctions()
        {
            _region    = RegionEndpoint.GetBySystemName(Environment.GetEnvironmentVariable("region"));
            _accessKey = Environment.GetEnvironmentVariable("accessKey");
            _secretKey = Environment.GetEnvironmentVariable("secretKey");
            _tableName = Environment.GetEnvironmentVariable("tableName");

            _responseHeader = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json" },
                { "Access-Control-Allow-Origin", "*" }
            };

            AWS.LoadAWSBasicCredentials(_region, _accessKey, _secretKey);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create an user record to database when user confirmed the email verification.
        /// </summary>
        /// <param name="context"></param>
        public CognitoContext FunctionHandler(CognitoContext model, ILambdaContext context)
        {
            AWS.LoadAWSBasicCredentials(_region, _accessKey, _secretKey);

            Console.WriteLine(JsonConvert.SerializeObject(model));

            if (model.TriggerSource == ConfirmSignUp)
            {
                try
                {
                    UserAttributes attributes = model.Request.UserAttributes;
                    Dictionary <string, AttributeValue> userAttributes = new Dictionary <string, AttributeValue>
                    {
                        ["Email"] = new AttributeValue()
                        {
                            S = attributes.CognitoEmail_Alias
                        },
                        ["EmailVerified"] = new AttributeValue()
                        {
                            BOOL = attributes.CognitoUser_Status == "CONFIRMED" ? true : false
                        },
                        ["FirstName"] = new AttributeValue()
                        {
                            S = attributes.Name.Split(' ')[0]
                        },
                        ["LastName"] = new AttributeValue()
                        {
                            S = attributes.Name.Split(' ')[1]
                        },
                        ["Mobile"] = new AttributeValue()
                        {
                            S = attributes.Phone_Number
                        },
                        ["MobileVerified"] = new AttributeValue()
                        {
                            BOOL = attributes.Phone_Number_Verified == "true" ? true : false
                        },
                        ["Birthdate"] = new AttributeValue()
                        {
                            S = attributes.Birthdate.ToString()
                        },
                        ["Gender"] = new AttributeValue()
                        {
                            S = EMPTY_STRING
                        },
                        ["Address"] = new AttributeValue()
                        {
                            S = EMPTY_STRING
                        },
                        ["Country"] = new AttributeValue()
                        {
                            S = EMPTY_STRING
                        },
                        ["UserType"] = new AttributeValue()
                        {
                            S = UserType.Confirmed.ToString()
                        },
                        ["ImageUrl"] = new AttributeValue()
                        {
                            S = EMPTY_STRING
                        },
                        ["Active"] = new AttributeValue()
                        {
                            BOOL = true
                        },
                        ["CreatedOn"] = new AttributeValue()
                        {
                            S = DateTime.UtcNow.ToLongDateString()
                        },
                        ["ModifiedOn"] = new AttributeValue()
                        {
                            S = DateTime.UtcNow.ToLongDateString()
                        }
                    };

                    var response = AWS.DynamoDB.PutItemAsync(new PutItemRequest()
                    {
                        TableName = _tableName,
                        Item      = userAttributes
                    }).GetAwaiter().GetResult();

                    if (response.HttpStatusCode != System.Net.HttpStatusCode.OK && response.HttpStatusCode != System.Net.HttpStatusCode.Accepted)
                    {
                        throw new Exception(string.Format("Failed to create a confirmed user - {0}", userAttributes["Email"].S.ToString()));
                    }
                }
                catch (AmazonDynamoDBException exception)
                {
                    Logger.Instance.LogException(exception);
                }
                catch (Exception exception)
                {
                    Logger.Instance.LogException(exception);
                }
            }

            return(model);
        }
Ejemplo n.º 4
0
        public void AWSClientWithBasicCredentialsTest()
        {
            AWS.LoadAWSBasicCredentials(_region, _accessKey, _secretKey);

            #region S3

            string bucketName = "awssimpletclienttest-s3bucket";
            //Create Bucket
            var grant = new S3Grant()
            {
                Permission = S3Permission.FULL_CONTROL,
                Grantee    = new S3Grantee {
                    EmailAddress = _testEmail
                }
            };

            var putBucketResponse = AWS.S3.PutBucketAsync(new PutBucketRequest()
            {
                BucketName       = bucketName,
                BucketRegion     = S3Region.APS1,
                BucketRegionName = "ap-southeast-1",
                Grants           = new List <S3Grant>()
                {
                    grant
                },
            }).GetAwaiter().GetResult();

            Assert.IsNotNull(putBucketResponse);
            Assert.IsTrue(putBucketResponse.HttpStatusCode == System.Net.HttpStatusCode.OK || putBucketResponse.HttpStatusCode == System.Net.HttpStatusCode.Accepted);

            //Delete Bucket
            var deleteBucketResponse = AWS.S3.DeleteBucketAsync(new DeleteBucketRequest()
            {
                BucketName      = bucketName,
                BucketRegion    = S3Region.APS1,
                UseClientRegion = true,
            }).GetAwaiter().GetResult();

            Assert.IsNotNull(deleteBucketResponse);

            #endregion

            #region DynamoDB
            string tableName = "AWSSimpleClientDynamoTableTest";
            string hashKey   = "Name";

            //Create Table
            var createTableResponse = AWS.DynamoDB.CreateTableAsync(new CreateTableRequest()
            {
                TableName             = tableName,
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 3,
                    WriteCapacityUnits = 1
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = hashKey,
                        KeyType       = KeyType.HASH
                    }
                },
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition {
                        AttributeName = hashKey,
                        AttributeType = ScalarAttributeType.S
                    }
                }
            }).GetAwaiter().GetResult();

            Assert.IsNotNull(createTableResponse);
            Assert.IsTrue(createTableResponse.HttpStatusCode == System.Net.HttpStatusCode.OK);

            Thread.Sleep(15000);

            //Delete Table
            var deleteTableResponse = AWS.DynamoDB.DeleteTableAsync(new DeleteTableRequest()
            {
                TableName = tableName,
            }).GetAwaiter().GetResult();

            Assert.IsNotNull(deleteTableResponse);
            Assert.IsTrue(deleteTableResponse.HttpStatusCode == System.Net.HttpStatusCode.OK);

            #endregion
        }