public HomeController(IConfiguration configuration) { _configuration = configuration; AWSSDKHandler.RegisterXRayForAllServices(); }
/// <summary> /// Default Constructor /// </summary> public Function() { AWSSDKHandler.RegisterXRayForAllServices(); _incidentRepository = new IncidentRepository(Environment.GetEnvironmentVariable("TABLE_NAME")); }
/// <summary> /// Constructor used for testing purposes /// </summary> /// <param name="ddbClient">Instance of DynamoDB client</param> /// <param name="tablename">DynamoDB table name</param> public Function(IAmazonDynamoDB ddbClient, string tablename) { AWSSDKHandler.RegisterXRayForAllServices(); _incidentRepository = new IncidentRepository(ddbClient, tablename); }
public Function() { AWSSDKHandler.RegisterXRayForAllServices(); _logger = CreateLogger(); _config = BuildConfiguration(); }
public Function(IIncidentRepository incidentRepository) { _incidentRepository = incidentRepository; AWSSDKHandler.RegisterXRayForAllServices(); }
public static BudgetDetail GetApiBudget(string accessToken, string userId) { AWSSDKHandler.RegisterXRayForAllServices(); AWSXRayRecorder.Instance.BeginSubsegment("MyBudgetExplorer.Models.Cache.GetApiBudget()"); try { var binaryFormatter = new BinaryFormatter(); var aesKey = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(userId)); var aesIV = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(userId)); var hash = BitConverter.ToString(aesKey).Replace("-", "").ToLower(); var fileName = $"budget.{hash}"; var tempFilePath = Path.Combine(Path.GetTempPath(), fileName); BudgetDetail budget = null; byte[] encrypted = null; var api = new YnabApi(accessToken); var tempBudget = api.GetBudget(); budget = tempBudget.Data.Budget; budget.LastModifiedOn = DateTime.UtcNow; using (var ms = new MemoryStream()) { binaryFormatter.Serialize(ms, budget); encrypted = EncryptAES(ms.ToArray(), aesKey, aesIV); } // Store S3 File if (!string.IsNullOrWhiteSpace(awsAccessKey) && !string.IsNullOrWhiteSpace(awsSecretKey)) { using (IAmazonS3 client = new AmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.USEast2)) { using (var ms = new MemoryStream(encrypted)) { var putrequest = new PutObjectRequest { BucketName = bucketName, Key = fileName, InputStream = ms }; client.PutObjectAsync(putrequest).Wait(); } } } // Store Local File if (encrypted != null && encrypted.Length > 0) { File.WriteAllBytes(tempFilePath, encrypted); File.SetCreationTimeUtc(tempFilePath, budget.LastModifiedOn); File.SetLastWriteTimeUtc(tempFilePath, budget.LastModifiedOn); } return(budget); } finally { AWSXRayRecorder.Instance.EndSubsegment(); } }
public Function() { AWSSDKHandler.RegisterXRayForAllServices(); }
public Function() { AWSSDKHandler.RegisterXRayForAllServices(); _client = new AmazonDynamoDBClient(RegionEndpoint.APSoutheast2); _table_name = Environment.GetEnvironmentVariable("TABLE_NAME"); }
public Function() { AWSSDKHandler.RegisterXRayForAllServices(); _client = new AmazonSimpleNotificationServiceClient(RegionEndpoint.APSoutheast2); _topicArn = Environment.GetEnvironmentVariable("TOPIC_ARN"); }
static WorkerEntryPoint() { AWSSDKHandler.RegisterXRayForAllServices(); }
public Startup(IConfiguration configuration) { AWSXRayRecorder.InitializeInstance(configuration: Configuration); // Inititalizing Configuration object with X-Ray recorder AWSSDKHandler.RegisterXRayForAllServices(); // All AWS SDK requests will be traced }
// Lambda constructor public LambdaFunctionBase() : this(GetRegionEndpoint(), GetEnvironment()) { AWSSDKHandler.RegisterXRayForAllServices(); }
public Startup(IConfiguration configuration) { Configuration = configuration; AWSXRayRecorder.InitializeInstance(configuration); AWSSDKHandler.RegisterXRayForAllServices(); }
public Function() { AWSSDKHandler.RegisterXRayForAllServices(); _simpleNotificationService = new AmazonSimpleNotificationServiceClient(); _topicArn = Environment.GetEnvironmentVariable("TOPIC_ARN"); }
public Startup(IConfiguration configuration) { Configuration = configuration; AWSSDKHandler.RegisterXRayForAllServices(); }
/// <summary> /// This function sets up the logging/tracing /// </summary> private void initFunction() { AWSSDKHandler.RegisterXRayForAllServices(); }
public static BudgetDetail GetS3Budget(string userId) { AWSSDKHandler.RegisterXRayForAllServices(); AWSXRayRecorder.Instance.BeginSubsegment("MyBudgetExplorer.Models.Cache.GetS3Budget()"); try { if (string.IsNullOrWhiteSpace(awsAccessKey) || string.IsNullOrWhiteSpace(awsSecretKey)) { return(null); } var binaryFormatter = new BinaryFormatter(); var aesKey = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(userId)); var aesIV = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(userId)); var hash = BitConverter.ToString(aesKey).Replace("-", "").ToLower(); var fileName = $"budget.{hash}"; var tempFilePath = Path.Combine(Path.GetTempPath(), fileName); BudgetDetail budget = null; using (IAmazonS3 client = new AmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.USEast2)) { byte[] encrypted = null; GetObjectRequest request = new GetObjectRequest { BucketName = bucketName, Key = fileName }; try { using (GetObjectResponse response = client.GetObjectAsync(request).Result) { byte[] buffer = new byte[128 * 1024]; using (MemoryStream ms = new MemoryStream()) { int read; while ((read = response.ResponseStream.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } encrypted = ms.ToArray(); } } var decrypted = DecryptAES(encrypted, aesKey, aesIV); using (var ms = new MemoryStream(decrypted)) { budget = (BudgetDetail)binaryFormatter.Deserialize(ms); } if (encrypted != null && encrypted.Length > 0) { File.WriteAllBytes(tempFilePath, encrypted); File.SetCreationTimeUtc(tempFilePath, budget.LastModifiedOn); File.SetLastWriteTimeUtc(tempFilePath, budget.LastModifiedOn); } } catch { } return(budget); } } finally { AWSXRayRecorder.Instance.EndSubsegment(); } }
public Function() { AWSXRayRecorder.InitializeInstance(); AWSSDKHandler.RegisterXRayForAllServices(); }
public ChatFunctions() { AWSSDKHandler.RegisterXRayForAllServices(); _serviceProvider = ChatDependencyContainerBuilder.Build(); }
public ScoringWorker() : this(lambdaLogger => new LambdaLogWriterFactory(lambdaLogger), new ScoringDependencies()) { AWSSDKHandler.RegisterXRayForAllServices(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => { builder.AllowAnyOrigin(); builder.AllowAnyHeader(); builder.AllowAnyMethod(); builder.AllowCredentials(); }); }); // Add cognito group authorization requirements for SiteAdmin and RegisteredUser services.AddAuthorization( options => { options.AddPolicy("IsSiteAdmin", policy => policy.Requirements.Add(new CognitoGroupAuthorizationRequirement("SiteAdmin"))); options.AddPolicy("IsRegisteredUser", policy => policy.Requirements.Add(new CognitoGroupAuthorizationRequirement("RegisteredUser"))); } ); services.AddSingleton <IXmlRepository, DdbXmlRepository>(); services.AddDistributedDynamoDbCache(o => { o.TableName = "TechSummitSessionState"; o.IdleTimeout = TimeSpan.FromMinutes(30); }); services.AddSession(o => { o.IdleTimeout = TimeSpan.FromMinutes(30); o.Cookie.HttpOnly = true; }); services.AddAuthentication(options => options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.Audience = "288seubnkumcdnj3odpftsvbjl"; options.Authority = "https://cognito-idp.us-west-2.amazonaws.com/us-west-2_megh2msxd"; options.RequireHttpsMetadata = false; //set this to true for prod environments! options.SaveToken = true; }); // Add a single instance (singleton) of the cognito authorization handler services.AddSingleton <IAuthorizationHandler, CognitoGroupAuthorizationHandler>(); //configure XRay, and register all AWS service calls to be traced AWSXRayRecorder.InitializeInstance(Configuration); // pass IConfiguration object that reads appsettings.json file AWSSDKHandler.RegisterXRayForAllServices(); //add DynamoDB and SSM to DI services.AddAWSService <IAmazonDynamoDB>(); //services.AddAWSService<IAmazonSimpleSystemsManagement>(); // only required if using ParameterStore to store keys (PsXmlRepository) services.AddMvc(); services.AddDefaultAWSOptions(Configuration.GetAWSOptions()); //Explicitly set the DataProtection middleware to store cookie encryption keys in DynamoDB var sp = services.BuildServiceProvider(); services.AddDataProtection().AddKeyManagementOptions(o => o.XmlRepository = sp.GetService <IXmlRepository>()); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("docs", new Info { Title = "re:Invent WIN401 Cart API", Version = "v1" }); }); }
protected BaseFunction() { AWSSDKHandler.RegisterXRayForAllServices(); _handler = CreateHandler(LambdaConfig.CreateSender()); }