Skip to content

Commit f52cad1

Browse files
committed
Fix types
1 parent 9e8a961 commit f52cad1

File tree

2 files changed

+46
-45
lines changed

2 files changed

+46
-45
lines changed

src/infra/docs-lambda-index-publisher/Models.cs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,51 @@
33
// See the LICENSE file in the project root for more information
44

55
using System.Text.Json.Serialization;
6+
using Amazon.Lambda.S3Events;
67
using Amazon.Lambda.SQSEvents;
78

89
namespace Elastic.Documentation.Lambda.LinkIndexUploader;
910

1011
[JsonSerializable(typeof(SQSEvent))]
1112
[JsonSerializable(typeof(S3Event))]
12-
[JsonSerializable(typeof(S3EventNotification))]
1313
[JsonSerializable(typeof(SQSBatchResponse))]
1414
public partial class LinkIndexUpdaterSerializerContext : JsonSerializerContext;
1515

16-
public class S3EventNotification
17-
{
18-
[JsonPropertyName("Records")]
19-
public List<S3EventRecord> Records { get; set; } = [];
20-
}
21-
22-
public class S3EventRecord
23-
{
24-
[JsonPropertyName("s3")]
25-
public S3Event S3 { get; set; } = new();
26-
27-
[JsonPropertyName("eventTime")]
28-
public DateTime EventTime { get; set; }
29-
}
30-
31-
public class S3Event
32-
{
33-
[JsonPropertyName("object")]
34-
public S3Object Obj { get; set; } = new();
35-
36-
[JsonPropertyName("bucket")]
37-
public S3Bucket Bucket { get; set; } = new();
38-
}
39-
40-
public class S3Bucket
41-
{
42-
[JsonPropertyName("name")]
43-
public string Name { get; set; } = string.Empty;
44-
}
45-
46-
public class S3Object
47-
{
48-
[JsonPropertyName("key")]
49-
public string Key { get; set; } = string.Empty;
50-
51-
[JsonPropertyName("eTag")]
52-
public string ETag { get; set; } = string.Empty;
53-
}
16+
// public class S3EventNotification
17+
// {
18+
// [JsonPropertyName("Records")]
19+
// public List<S3EventRecord> Records { get; set; } = [];
20+
// }
21+
22+
// public class S3EventRecord
23+
// {
24+
// [JsonPropertyName("s3")]
25+
// public S3Event S3 { get; set; } = new();
26+
//
27+
// [JsonPropertyName("eventTime")]
28+
// public DateTime EventTime { get; set; }
29+
// }
30+
//
31+
// public class S3Event
32+
// {
33+
// [JsonPropertyName("object")]
34+
// public S3Object Obj { get; set; } = new();
35+
//
36+
// [JsonPropertyName("bucket")]
37+
// public S3Bucket Bucket { get; set; } = new();
38+
// }
39+
//
40+
// public class S3Bucket
41+
// {
42+
// [JsonPropertyName("name")]
43+
// public string Name { get; set; } = string.Empty;
44+
// }
45+
//
46+
// public class S3Object
47+
// {
48+
// [JsonPropertyName("key")]
49+
// public string Key { get; set; } = string.Empty;
50+
//
51+
// [JsonPropertyName("eTag")]
52+
// public string ETag { get; set; } = string.Empty;
53+
// }

src/infra/docs-lambda-index-publisher/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text.Json;
77
using Amazon.Lambda.Core;
88
using Amazon.Lambda.RuntimeSupport;
9+
using Amazon.Lambda.S3Events;
910
using Amazon.Lambda.Serialization.SystemTextJson;
1011
using Amazon.Lambda.SQSEvents;
1112
using Amazon.S3;
@@ -106,19 +107,19 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
106107
}
107108
}
108109

109-
static async Task<IReadOnlyCollection<(S3EventRecord, LinkReference)>> GetLinkReferences(IAmazonS3 s3Client, SQSEvent.SQSMessage message, ILambdaContext context)
110+
static async Task<IReadOnlyCollection<(S3Event.S3EventNotificationRecord, LinkReference)>> GetLinkReferences(IAmazonS3 s3Client, SQSEvent.SQSMessage message, ILambdaContext context)
110111
{
111112
if (string.IsNullOrEmpty(message.Body))
112113
throw new Exception("No Body in SQS Message.");
113114
context.Logger.LogDebug("Received message {messageBody}", message.Body);
114-
var s3Event = JsonSerializer.Deserialize<S3EventNotification>(message.Body, LinkIndexUpdaterSerializerContext.Default.S3EventNotification);
115+
var s3Event = JsonSerializer.Deserialize<S3Event>(message.Body, LinkIndexUpdaterSerializerContext.Default.S3Event);
115116
if (s3Event?.Records == null || s3Event.Records.Count == 0)
116117
throw new Exception("Invalid S3 event message format");
117-
var linkReferences = new ConcurrentBag<(S3EventRecord, LinkReference)>();
118+
var linkReferences = new ConcurrentBag<(S3Event.S3EventNotificationRecord, LinkReference)>();
118119
await Parallel.ForEachAsync(s3Event.Records, async (record, ctx) =>
119120
{
120121
var s3Bucket = record.S3.Bucket;
121-
var s3Object = record.S3.Obj;
122+
var s3Object = record.S3.Object;
122123
context.Logger.LogInformation("Get object {key} from bucket {bucketName}", s3Object.Key, s3Bucket.Name);
123124
var getObjectResponse = await s3Client.GetObjectAsync(s3Bucket.Name, s3Object.Key, ctx);
124125
await using var stream = getObjectResponse.ResponseStream;
@@ -130,9 +131,9 @@ await Parallel.ForEachAsync(s3Event.Records, async (record, ctx) =>
130131
return linkReferences;
131132
}
132133

133-
static void UpdateLinkIndex(LinkIndex linkIndex, LinkReference linkReference, S3EventRecord s3EventRecord, ILambdaContext context)
134+
static void UpdateLinkIndex(LinkIndex linkIndex, LinkReference linkReference, S3Event.S3EventNotificationRecord s3EventRecord, ILambdaContext context)
134135
{
135-
var s3Object = s3EventRecord.S3.Obj;
136+
var s3Object = s3EventRecord.S3.Object;
136137
var keyTokens = s3Object.Key.Split('/');
137138
var repository = keyTokens[1];
138139
var branch = keyTokens[2];

0 commit comments

Comments
 (0)