private void SetupGeoDataManager()
        {
            var accessKey  = ConfigurationManager.AppSettings["AWS_ACCESS_KEY_ID"];
            var secretKey  = ConfigurationManager.AppSettings["AWS_SECRET_KEY"];
            var tableName  = ConfigurationManager.AppSettings["PARAM1"];
            var regionName = ConfigurationManager.AppSettings["PARAM2"];


            var region = RegionEndpoint.GetBySystemName(regionName);
            var config = new AmazonDynamoDBConfig {
                MaxErrorRetry = 20, RegionEndpoint = region
            };


            var creds = new BasicAWSCredentials(accessKey, secretKey);


            bool useLocalDb;

            bool.TryParse(ConfigurationManager.AppSettings["AWS_USE_LOCAL_DB"], out useLocalDb);

            if (useLocalDb)
            {
                var localDB = ConfigurationManager.AppSettings["AWS_LOCAL_DYNAMO_DB_ENDPOINT"];
                config.ServiceURL = localDB;
            }

            var ddb = new AmazonDynamoDBClient(creds, config);

            _config         = new GeoDataManagerConfiguration(ddb, tableName);
            _geoDataManager = new GeoDataManager(_config);
        }
        private void Init()
        {
            var ddb = new AmazonDynamoDBClient();

            _config         = new GeoDataManagerConfiguration(ddb, _tableName);
            _geoDataManager = new GeoDataManager(_config);
        }
        public async Task <string> FunctionHandler(ResponseSourse json, ILambdaContext context)
        {
            context.Logger.LogLine($"Beginning to process {context.FunctionName} records...");
            var photoJsonData = json;

            //return "";
            context.Logger.LogLine($"Create context {context.FunctionName}...");

            var config = new GeoDataManagerConfiguration(new AmazonDynamoDBClient(), _tableName);
            var ddb    = new AmazonDynamoDBClient();

            _config         = new GeoDataManagerConfiguration(ddb, _tableName);
            _geoDataManager = new GeoDataManager(_config);

            var items = photoJsonData.response.items.ToList();

            for (int i = 0; i < items.Count; i++)
            {
                var item        = items.ElementAt(i);
                var imgUrl      = item.sizes.FirstOrDefault(x => x.type == "p")?.url;
                var imgUrlLarge = item.sizes.FirstOrDefault(x => x.type == "w")?.url;

                if (String.IsNullOrEmpty(imgUrl) || String.IsNullOrEmpty(imgUrlLarge))
                {
                    continue;
                }

                var guid      = Guid.NewGuid();
                var latitude  = item.lat;
                var longitude = item.@long;

                var point = new GeoPoint(latitude, longitude);

                var rangeKeyVal = new AttributeValue {
                    S = guid.ToString()
                };
                var imgUrlVal = new AttributeValue {
                    S = imgUrl
                };
                var imgUrlLargeVal = new AttributeValue {
                    S = imgUrlLarge
                };

                var req = new PutPointRequest(point, rangeKeyVal);
                req.PutItemRequest.Item["imgUrl"]      = imgUrlVal;
                req.PutItemRequest.Item["imgUrlLarge"] = imgUrlLargeVal;

                await _geoDataManager.PutPointAsync(req);
            }

            context.Logger.LogLine("Stream processing complete.");
            return(true.ToString());
        }
Exemple #4
0
        private async Task CreateTable()
        {
            var config = new GeoDataManagerConfiguration(new AmazonDynamoDBClient(), _tableName);

            try
            {
                var ctr = GeoTableUtil.GetCreateTableRequest(config);

                var ddb = new AmazonDynamoDBClient();
                _config         = new GeoDataManagerConfiguration(ddb, _tableName);
                _geoDataManager = new GeoDataManager(_config);

                await config.DynamoDBClient.CreateTableAsync(ctr);
                await InsertData();
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void SetupGeoDataManager()
        {
            var accessKey  = "test";      // ConfigurationManager.AppSettings["AWS_ACCESS_KEY_ID"];
            var secretKey  = "test";      // ConfigurationManager.AppSettings["AWS_SECRET_KEY"];
            var tableName  = "Practices"; // ConfigurationManager.AppSettings["PARAM1"];
            var regionName = "us-east-1"; // ConfigurationManager.AppSettings["PARAM2"];
            var region     = RegionEndpoint.GetBySystemName(regionName);
            var localDB    = "http://localhost:8000";
            var config     = new AmazonDynamoDBConfig
            {
                MaxErrorRetry = 20
                ,
                RegionEndpoint = region
                ,
                ServiceURL = localDB
                ,
                AuthenticationRegion = regionName
            };

            _creds          = new BasicAWSCredentials(accessKey, secretKey);
            _ddb            = new AmazonDynamoDBClient(_creds, config);
            _config         = new GeoDataManagerConfiguration(_ddb, tableName);
            _geoDataManager = new GeoDataManager(_config);
        }
Exemple #6
0
        public static CreateTableRequest GetCreateTableRequest(GeoDataManagerConfiguration config)
        {
            var req = new CreateTableRequest
            {
                TableName             = config.TableName,
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 10,
                    WriteCapacityUnits = 5
                },
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        KeyType       = KeyType.HASH,
                        AttributeName = config.HashKeyAttributeName
                    },
                    new KeySchemaElement
                    {
                        KeyType       = KeyType.RANGE,
                        AttributeName = config.RangeKeyAttributeName
                    },
                },

                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeType = ScalarAttributeType.N,
                        AttributeName = config.HashKeyAttributeName
                    },
                    new AttributeDefinition
                    {
                        AttributeType = ScalarAttributeType.S,
                        AttributeName = config.RangeKeyAttributeName,
                    },
                    new AttributeDefinition
                    {
                        AttributeType = ScalarAttributeType.N,
                        AttributeName = config.GeohashAttributeName
                    }
                },
                LocalSecondaryIndexes = new List <LocalSecondaryIndex>
                {
                    new LocalSecondaryIndex
                    {
                        IndexName = config.GeohashIndexName,
                        KeySchema = new List <KeySchemaElement>
                        {
                            new KeySchemaElement
                            {
                                KeyType       = KeyType.HASH,
                                AttributeName = config.HashKeyAttributeName
                            },
                            new KeySchemaElement
                            {
                                KeyType       = KeyType.RANGE,
                                AttributeName = config.GeohashAttributeName
                            }
                        },
                        Projection = new Projection
                        {
                            ProjectionType = ProjectionType.ALL
                        }
                    }
                }
            };

            return(req);
        }
Exemple #7
0
 public DynamoDBManager(GeoDataManagerConfiguration config)
 {
     _config = config;
 }