Skip to content

Commit 4329775

Browse files
authored
Remove SDK dependency from DynamoDBEvent (#1648)
* refactor: Remove SDK dependency from DynamoDBEvent * refactor: Address PR feedback
1 parent 9a0d0b4 commit 4329775

File tree

7 files changed

+392
-43
lines changed

7 files changed

+392
-43
lines changed

Libraries/src/Amazon.Lambda.DynamoDBEvents/Amazon.Lambda.DynamoDBEvents.csproj

+7-11
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,26 @@
33
<Import Project="..\..\..\buildtools\common.props" />
44

55
<PropertyGroup>
6-
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net8.0</TargetFrameworks>
6+
<TargetFrameworks>netcoreapp3.1;net8.0</TargetFrameworks>
77
<Description>Amazon Lambda .NET Core support - DynamoDBEvents package.</Description>
88
<AssemblyTitle>Amazon.Lambda.DynamoDBEvents</AssemblyTitle>
9-
<VersionPrefix>2.3.0</VersionPrefix>
9+
<VersionPrefix>3.0.0</VersionPrefix>
1010
<AssemblyName>Amazon.Lambda.DynamoDBEvents</AssemblyName>
1111
<PackageId>Amazon.Lambda.DynamoDBEvents</PackageId>
1212
<PackageTags>AWS;Amazon;Lambda</PackageTags>
1313
</PropertyGroup>
1414

15-
<ItemGroup>
16-
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.3.24" />
17-
</ItemGroup>
18-
1915
<ItemGroup>
2016
<Compile Remove="Converters\DictionaryLongToStringJsonConverter.cs" />
2117
</ItemGroup>
2218

2319
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' ">
2420
<Compile Include="Converters\DictionaryLongToStringJsonConverter.cs" />
2521
</ItemGroup>
26-
27-
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
28-
<WarningsAsErrors>IL2026,IL2067,IL2075</WarningsAsErrors>
29-
<IsTrimmable>true</IsTrimmable>
22+
23+
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
24+
<WarningsAsErrors>IL2026,IL2067,IL2075</WarningsAsErrors>
25+
<IsTrimmable>true</IsTrimmable>
3026
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
31-
</PropertyGroup>
27+
</PropertyGroup>
3228
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
namespace Amazon.Lambda.DynamoDBEvents
22
{
3-
using Amazon.DynamoDBv2.Model;
43
using System;
54
using System.Collections.Generic;
5+
using System.IO;
66

77
/// <summary>
88
/// AWS DynamoDB event
99
/// http://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html
1010
/// http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-ddb-update
1111
/// </summary>
12-
#if NET8_0_OR_GREATER
13-
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("DynamoDBEvent has a reference to the AWS SDK for .NET. The ConstantClass used to represent enums in the SDK is not supported in the Lambda serializer SourceGeneratorLambdaJsonSerializer for trimming scenarios.")]
14-
#endif
1512
public class DynamoDBEvent
1613
{
1714
/// <summary>
@@ -21,15 +18,315 @@ public class DynamoDBEvent
2118

2219
/// <summary>
2320
/// DynamoDB stream record
24-
/// http://docs.aws.amazon.com/dynamodbstreams/latest/APIReference/API_StreamRecord.html
21+
/// https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_Record.html
2522
/// </summary>
26-
public class DynamodbStreamRecord : Record
23+
public class DynamodbStreamRecord
2724
{
2825
/// <summary>
2926
/// The event source arn of DynamoDB.
3027
/// </summary>
3128
public string EventSourceArn { get; set; }
29+
30+
/// <summary>
31+
/// The region in which the <c>GetRecords</c> request was received.
32+
/// </summary>
33+
public string AwsRegion { get; set; }
34+
35+
/// <summary>
36+
/// The main body of the stream record, containing all of the DynamoDB-specific fields.
37+
/// </summary>
38+
public StreamRecord Dynamodb { get; set; }
39+
40+
/// <summary>
41+
/// A globally unique identifier for the event that was recorded in this stream record.
42+
/// </summary>
43+
public string EventID { get; set; }
44+
45+
/// <summary>
46+
/// <para>
47+
/// The type of data modification that was performed on the DynamoDB table:
48+
/// </para>
49+
/// <ul>
50+
/// <li>
51+
/// <para>
52+
/// <c>INSERT</c> - a new item was added to the table.
53+
/// </para>
54+
/// </li>
55+
///
56+
/// <li>
57+
/// <para>
58+
/// <c>MODIFY</c> - one or more of an existing item's attributes were modified.
59+
/// </para>
60+
/// </li>
61+
///
62+
/// <li>
63+
/// <para>
64+
/// <c>REMOVE</c> - the item was deleted from the table
65+
/// </para>
66+
/// </li>
67+
/// </ul>
68+
/// </summary>
69+
public string EventName { get; set; }
70+
71+
/// <summary>
72+
/// The Amazon Web Services service from which the stream record originated. For DynamoDB
73+
/// Streams, this is <c>aws:dynamodb</c>.
74+
/// </summary>
75+
public string EventSource { get; set; }
76+
77+
/// <summary>
78+
/// <para>
79+
/// The version number of the stream record format. This number is updated whenever the
80+
/// structure of <c>Record</c> is modified.
81+
/// </para>
82+
///
83+
/// <para>
84+
/// Client applications must not assume that <c>eventVersion</c> will remain at
85+
/// a particular value, as this number is subject to change at any time. In general, <c>eventVersion</c>
86+
/// will only increase as the low-level DynamoDB Streams API evolves.
87+
/// </para>
88+
/// </summary>
89+
public string EventVersion { get; set; }
90+
91+
/// <summary>
92+
/// <para>Items that are deleted by the Time to Live process after expiration have the following fields:</para>
93+
/// <ul>
94+
/// <li>
95+
/// <para>Records[].userIdentity.type</para>
96+
/// <para>"Service"</para>
97+
/// </li>
98+
/// <li>
99+
/// <para>Records[].userIdentity.principalId</para>
100+
/// <para>"dynamodb.amazonaws.com"</para>
101+
/// </li>
102+
/// </ul>
103+
/// </summary>
104+
public Identity UserIdentity { get; set; }
32105
}
33106

107+
/// <summary>
108+
/// A description of a single data modification that was performed on an item in a DynamoDB table.
109+
/// </summary>
110+
public class StreamRecord
111+
{
112+
/// <summary>
113+
/// The approximate date and time when the stream record was created, in <a href="http://www.epochconverter.com/">UNIX
114+
/// epoch time</a> format and rounded down to the closest second.
115+
/// </summary>
116+
public DateTime ApproximateCreationDateTime { get; set; }
117+
118+
/// <summary>
119+
/// The primary key attribute(s) for the DynamoDB item that was modified.
120+
/// </summary>
121+
public Dictionary<string, AttributeValue> Keys { get; set; }
122+
123+
/// <summary>
124+
/// The item in the DynamoDB table as it appeared after it was modified.
125+
/// </summary>
126+
public Dictionary<string, AttributeValue> NewImage { get; set; }
127+
128+
/// <summary>
129+
/// The item in the DynamoDB table as it appeared before it was modified.
130+
/// </summary>
131+
public Dictionary<string, AttributeValue> OldImage { get; set; }
132+
133+
/// <summary>
134+
/// The sequence number of the stream record.
135+
/// </summary>
136+
public string SequenceNumber { get; set; }
137+
138+
/// <summary>
139+
/// The size of the stream record, in bytes.
140+
/// </summary>
141+
public long SizeBytes { get; set; }
142+
143+
/// <summary>
144+
/// <para>
145+
/// The type of data from the modified DynamoDB item that was captured in this stream record:
146+
/// </para>
147+
///
148+
/// <ul>
149+
/// <li>
150+
/// <para>
151+
/// <c>KEYS_ONLY</c> - only the key attributes of the modified item.
152+
/// </para>
153+
/// </li>
154+
///
155+
/// <li>
156+
/// <para>
157+
/// <c>NEW_IMAGE</c> - the entire item, as it appeared after it was modified.
158+
/// </para>
159+
/// </li>
160+
///
161+
/// <li>
162+
/// <para>
163+
/// <c>OLD_IMAGE</c> - the entire item, as it appeared before it was modified.
164+
/// </para>
165+
/// </li>
166+
///
167+
/// <li>
168+
/// <para>
169+
/// <c>NEW_AND_OLD_IMAGES</c> - both the new and the old item images of the item.
170+
/// </para>
171+
/// </li>
172+
/// </ul>
173+
/// </summary>
174+
public string StreamViewType { get; set; }
175+
}
176+
177+
/// <summary>
178+
/// Contains details about the type of identity that made the request.
179+
/// </summary>
180+
public class Identity
181+
{
182+
/// <summary>
183+
/// A unique identifier for the entity that made the call. For Time To Live, the principalId
184+
/// is "dynamodb.amazonaws.com".
185+
/// </summary>
186+
public string PrincipalId { get; set; }
187+
188+
/// <summary>
189+
/// The type of the identity. For Time To Live, the type is "Service".
190+
/// </summary>
191+
public string Type { get; set; }
192+
}
193+
194+
/// <summary>
195+
/// Represents the data for an attribute.
196+
///
197+
/// <para>
198+
/// Each attribute value is described as a name-value pair. The name is the data type,
199+
/// and the value is the data itself.
200+
/// </para>
201+
///
202+
/// <para>
203+
/// For more information, see <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypes">Data
204+
/// Types</a> in the <i>Amazon DynamoDB Developer Guide</i>.
205+
/// </para>
206+
/// </summary>
207+
public class AttributeValue
208+
{
209+
/// <summary>
210+
/// <para>
211+
/// An attribute of type Binary. For example:
212+
/// </para>
213+
///
214+
/// <para>
215+
/// <c>"B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk"</c>
216+
/// </para>
217+
/// </summary>
218+
public MemoryStream B { get; set; }
219+
220+
/// <summary>
221+
/// <para>
222+
/// An attribute of type Boolean. For example:
223+
/// </para>
224+
///
225+
/// <para>
226+
/// <c>"BOOL": true</c>
227+
/// </para>
228+
/// </summary>
229+
public bool? BOOL { get; set; }
230+
231+
/// <summary>
232+
/// <para>
233+
/// An attribute of type Binary Set. For example:
234+
/// </para>
235+
///
236+
/// <para>
237+
/// <c>"BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="]</c>
238+
/// </para>
239+
/// </summary>
240+
public List<MemoryStream> BS { get; set; }
241+
242+
/// <summary>
243+
/// <para>
244+
/// An attribute of type List. For example:
245+
/// </para>
246+
///
247+
/// <para>
248+
/// <c>"L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"N": "3.14159"}]</c>
249+
/// </para>
250+
/// </summary>
251+
public List<AttributeValue> L { get; set; }
252+
253+
/// <summary>
254+
/// <para>
255+
/// An attribute of type Map. For example:
256+
/// </para>
257+
///
258+
/// <para>
259+
/// <c>"M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}}</c>
260+
/// </para>
261+
/// </summary>
262+
public Dictionary<string, AttributeValue> M { get; set; }
263+
264+
/// <summary>
265+
/// <para>
266+
/// An attribute of type Number. For example:
267+
/// </para>
268+
///
269+
/// <para>
270+
/// <c>"N": "123.45"</c>
271+
/// </para>
272+
///
273+
/// <para>
274+
/// Numbers are sent across the network to DynamoDB as strings, to maximize compatibility
275+
/// across languages and libraries. However, DynamoDB treats them as number type attributes
276+
/// for mathematical operations.
277+
/// </para>
278+
/// </summary>
279+
public string N { get; set; }
280+
281+
/// <summary>
282+
/// <para>
283+
/// An attribute of type Number Set. For example:
284+
/// </para>
285+
///
286+
/// <para>
287+
/// <c>"NS": ["42.2", "-19", "7.5", "3.14"]</c>
288+
/// </para>
289+
///
290+
/// <para>
291+
/// Numbers are sent across the network to DynamoDB as strings, to maximize compatibility
292+
/// across languages and libraries. However, DynamoDB treats them as number type attributes
293+
/// for mathematical operations.
294+
/// </para>
295+
/// </summary>
296+
public List<string> NS { get; set; }
297+
298+
/// <summary>
299+
/// <para>
300+
/// An attribute of type Null. For example:
301+
/// </para>
302+
///
303+
/// <para>
304+
/// <c>"NULL": true</c>
305+
/// </para>
306+
/// </summary>
307+
public bool? NULL { get; set; }
308+
309+
/// <summary>
310+
/// <para>
311+
/// An attribute of type String. For example:
312+
/// </para>
313+
///
314+
/// <para>
315+
/// <c>"S": "Hello"</c>
316+
/// </para>
317+
/// </summary>
318+
public string S { get; set; }
319+
320+
/// <summary>
321+
/// <para>
322+
/// An attribute of type String Set. For example:
323+
/// </para>
324+
///
325+
/// <para>
326+
/// <c>"SS": ["Giraffe", "Hippo" ,"Zebra"]</c>
327+
/// </para>
328+
/// </summary>
329+
public List<string> SS { get; set; }
330+
}
34331
}
35332
}

Libraries/src/Amazon.Lambda.DynamoDBEvents/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
This package contains classes that can be used as input types for Lambda functions that process Amazon DynamoDB events.
44

5-
This package has a dependency on the [AWS SDK for .NET package DynamoDBv2](https://www.nuget.org/packages/AWSSDK.DynamoDBv2/) in order to use the `Amazon.DynamoDBv2.Model.Record` type.
6-
75
# Sample Function
86

97
The following is a sample class and Lambda function that receives Amazon DynamoDB event record data as an input and writes some of the incoming event data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)

Libraries/src/Amazon.Lambda.Serialization.Json/Amazon.Lambda.Serialization.Json.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AssemblyName>Amazon.Lambda.Serialization.Json</AssemblyName>
1010
<PackageId>Amazon.Lambda.Serialization.Json</PackageId>
1111
<PackageTags>AWS;Amazon;Lambda</PackageTags>
12-
<VersionPrefix>2.1.1</VersionPrefix>
12+
<VersionPrefix>2.2.0</VersionPrefix>
1313
</PropertyGroup>
1414

1515
<ItemGroup>

0 commit comments

Comments
 (0)