Skip to content

Commit 8793637

Browse files
committed
pr comments
1 parent 39d776c commit 8793637

5 files changed

Lines changed: 72 additions & 13 deletions

File tree

Libraries/src/Amazon.Lambda.Annotations/DynamoDB/DynamoDBEventAttribute.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@ public string ResourceName
3131
{
3232
return resourceName;
3333
}
34+
35+
if (string.IsNullOrWhiteSpace(Stream))
36+
{
37+
return string.Empty;
38+
}
39+
3440
if (Stream.StartsWith("@"))
3541
{
36-
return Stream.Substring(1);
42+
return Stream.Length > 1 ? Stream.Substring(1) : string.Empty;
3743
}
3844

3945
// DynamoDB stream ARN format: arn:aws:dynamodb:region:account:table/TableName/stream/timestamp
@@ -57,7 +63,7 @@ public string ResourceName
5763
/// </summary>
5864
public uint BatchSize
5965
{
60-
get => batchSize.GetValueOrDefault();
66+
get => batchSize.GetValueOrDefault(100);
6167
set => batchSize = value;
6268
}
6369
private uint? batchSize { get; set; }
@@ -75,7 +81,7 @@ public uint BatchSize
7581
/// </summary>
7682
public bool Enabled
7783
{
78-
get => enabled.GetValueOrDefault();
84+
get => enabled.GetValueOrDefault(true);
7985
set => enabled = value;
8086
}
8187
private bool? enabled { get; set; }
@@ -119,13 +125,21 @@ internal List<string> Validate()
119125
{
120126
validationErrors.Add($"{nameof(DynamoDBEventAttribute.MaximumBatchingWindowInSeconds)} = {MaximumBatchingWindowInSeconds}. It must be between 0 and 300");
121127
}
122-
if (!string.IsNullOrEmpty(StartingPosition) && StartingPosition != "TRIM_HORIZON" && StartingPosition != "LATEST")
128+
if (string.IsNullOrEmpty(StartingPosition))
129+
{
130+
validationErrors.Add($"{nameof(DynamoDBEventAttribute.StartingPosition)} must not be null or empty. It must be either TRIM_HORIZON or LATEST");
131+
}
132+
else if (StartingPosition != "TRIM_HORIZON" && StartingPosition != "LATEST")
123133
{
124134
validationErrors.Add($"{nameof(DynamoDBEventAttribute.StartingPosition)} = {StartingPosition}. It must be either TRIM_HORIZON or LATEST");
125135
}
126-
if (!Stream.StartsWith("@"))
136+
if (string.IsNullOrWhiteSpace(Stream))
137+
{
138+
validationErrors.Add($"{nameof(DynamoDBEventAttribute.Stream)} must not be null or empty");
139+
}
140+
else if (!Stream.StartsWith("@"))
127141
{
128-
if (!Stream.Contains(":dynamodb:") && !Stream.Contains("/stream/"))
142+
if (!Stream.Contains(":dynamodb:") || !Stream.Contains("/stream/"))
129143
{
130144
validationErrors.Add($"{nameof(DynamoDBEventAttribute.Stream)} = {Stream}. The DynamoDB stream ARN is invalid");
131145
}

Libraries/test/TestServerlessApp.IntegrationTests/IntegrationTestContextFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public async Task InitializeAsync()
8787
Console.WriteLine($"[IntegrationTest] TestTable: {testTableName}");
8888
if (!string.IsNullOrEmpty(testTableName))
8989
{
90-
var dynamoDbClient = new Amazon.DynamoDBv2.AmazonDynamoDBClient(Amazon.RegionEndpoint.USWest2);
90+
using var dynamoDbClient = new Amazon.DynamoDBv2.AmazonDynamoDBClient(Amazon.RegionEndpoint.USWest2);
9191
var describeTableResponse = await dynamoDbClient.DescribeTableAsync(testTableName);
9292
TestTableStreamARN = describeTableResponse.Table.LatestStreamArn;
9393
Console.WriteLine($"[IntegrationTest] TestTable Stream ARN: {TestTableStreamARN}");

Libraries/test/TestServerlessApp.IntegrationTests/TestServerlessApp.IntegrationTests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
@@ -8,7 +8,7 @@
88
<ItemGroup>
99
<!-- AWSSDK.SecurityToken is needed at runtime for environments which uses assume-role operation for credentials -->
1010
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.1.99" />
11-
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.*" />
11+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.513.1" />
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
1313
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1414
<PackageReference Include="xunit" Version="2.4.1" />

Libraries/test/TestServerlessApp/aws-lambda-tools-defaults.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"template": "serverless.template",
1414
"template-parameters": "",
1515
"docker-host-build-output-dir": "./bin/Release/lambda-publish",
16-
"s3-bucket": "test-serverless-app",
17-
"stack-name": "test-serverless-app",
18-
"function-architecture": "x86_64"
19-
}
16+
"s3-bucket" : "test-serverless-app-18716bb0",
17+
"stack-name" : "test-serverless-app-18716bb0",
18+
"function-architecture" : "x86_64"
19+
}

Libraries/test/TestServerlessApp/serverless.template

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,51 @@
14171417
},
14181418
"TestS3Bucket": {
14191419
"Type": "AWS::S3::Bucket"
1420+
},
1421+
"DynamoDBStreamHandler": {
1422+
"Type": "AWS::Serverless::Function",
1423+
"Metadata": {
1424+
"Tool": "Amazon.Lambda.Annotations",
1425+
"SyncedEvents": [
1426+
"TestTableStream"
1427+
],
1428+
"SyncedEventProperties": {
1429+
"TestTableStream": [
1430+
"Stream.Fn::GetAtt",
1431+
"StartingPosition",
1432+
"BatchSize"
1433+
]
1434+
}
1435+
},
1436+
"Properties": {
1437+
"MemorySize": 512,
1438+
"Timeout": 30,
1439+
"Policies": [
1440+
"AWSLambdaDynamoDBExecutionRole"
1441+
],
1442+
"PackageType": "Image",
1443+
"ImageUri": ".",
1444+
"ImageConfig": {
1445+
"Command": [
1446+
"TestServerlessApp::TestServerlessApp.DynamoDbStreamProcessing_HandleStream_Generated::HandleStream"
1447+
]
1448+
},
1449+
"Events": {
1450+
"TestTableStream": {
1451+
"Type": "DynamoDB",
1452+
"Properties": {
1453+
"StartingPosition": "TRIM_HORIZON",
1454+
"BatchSize": 100,
1455+
"Stream": {
1456+
"Fn::GetAtt": [
1457+
"TestTable",
1458+
"StreamArn"
1459+
]
1460+
}
1461+
}
1462+
}
1463+
}
1464+
}
14201465
}
14211466
}
14221467
}

0 commit comments

Comments
 (0)