Skip to content

remove S3 SDK deps #1237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@

<PropertyGroup>
<Description>Amazon Lambda .NET Core support - S3Events package.</Description>
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<AssemblyTitle>Amazon.Lambda.S3Events</AssemblyTitle>
<VersionPrefix>2.0.1</VersionPrefix>
<AssemblyName>Amazon.Lambda.S3Events</AssemblyName>
<PackageId>Amazon.Lambda.S3Events</PackageId>
<PackageTags>AWS;Amazon;Lambda</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="3.7.0" />
</ItemGroup>

</Project>
6 changes: 2 additions & 4 deletions Libraries/src/Amazon.Lambda.S3Events/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Amazon.Lambda.S3Events

This package contains classes that can be used as input types for Lambda functions that process Amazon Simple Storage Service (Amazon S3) events.

This package has a dependency on the [AWS SDK for .NET package AWSSDK.S3](https://www.nuget.org/packages/AWSSDK.S3/) in order to use the `Amazon.S3.Util.S3EventNotification` type.
This package contains classes that can be used as input types for Lambda functions that process Amazon Simple Storage Service (Amazon S3) events.

# Serialization

If you are using this package with Amazon Lambda but are not also using `Amazon.Lambda.Serialization.Json`, be aware that two properties require custom serialization. These properties are both part of the `Amazon.S3.Util.S3EventNotification+ResponseElementsEntity` class.
1. `XAmzRequestId` should be treated as `x-amz-request-id`
2. `XAmzId2` should be treated as `x-amz-id-2`

A Newtonsoft.Json `IContractResolver` implementation which handles this custom serialization is located in [Amazon.Lambda.Serialization.Json\AwsResolver.cs](../Amazon.Lambda.Serialization.Json/AwsResolver.cs), consult this source for more information.
A Newtonsoft.Json `IContractResolver` implementation which handles this custom serialization is located in [Amazon.Lambda.Serialization.Json\AwsResolver.cs](../Amazon.Lambda.Serialization.Json/AwsResolver.cs), consult this source for more information.

# Sample Function

Expand Down
222 changes: 219 additions & 3 deletions Libraries/src/Amazon.Lambda.S3Events/S3Event.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,227 @@
namespace Amazon.Lambda.S3Events
{
using Amazon.S3.Util;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

/// <summary>
/// AWS S3 event
/// http://docs.aws.amazon.com/lambda/latest/dg/with-s3.html
/// http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-s3-put
/// </summary>
public class S3Event : S3EventNotification { }
}

public class S3Event
{

/// <summary>
/// Gets and sets the records for the S3 event notification
/// </summary>
public List<S3EventNotificationRecord> Records { get; set; }

/// <summary>
/// The class holds the user identity properties.
/// </summary>
public class UserIdentityEntity
{
/// <summary>
/// Gets and sets the PrincipalId property.
/// </summary>
public string PrincipalId { get; set; }
}

/// <summary>
/// This class contains the identity information for an S3 bucket.
/// </summary>
public class S3BucketEntity
{
/// <summary>
/// Gets and sets the name of the bucket.
/// </summary>
public string Name { get; set; }

/// <summary>
/// Gets and sets the bucket owner id.
/// </summary>
public UserIdentityEntity OwnerIdentity { get; set; }

/// <summary>
/// Gets and sets the S3 bucket arn.
/// </summary>
public string Arn { get; set; }
}

/// <summary>
/// This class contains the information for an object in S3.
/// </summary>
public class S3ObjectEntity
{
/// <summary>
/// Gets and sets the key for the object stored in S3.
/// </summary>
public string Key { get; set; }

/// <summary>
/// Gets and sets the size of the object in S3.
/// </summary>
public long Size { get; set; }

/// <summary>
/// Gets and sets the etag of the object. This can be used to determine if the object has changed.
/// </summary>
public string ETag { get; set; }

/// <summary>
/// Gets and sets the version id of the object in S3.
/// </summary>
public string VersionId { get; set; }

/// <summary>
/// Gets and sets the sequencer a string representation of a hexadecimal value used to determine event sequence, only used with PUTs and DELETEs.
/// </summary>
public string Sequencer { get; set; }
}

/// <summary>
/// Gets and sets the meta information describing S3.
/// </summary>
public class S3Entity
{
/// <summary>
/// Gets and sets the ConfigurationId. This ID can be found in the bucket notification configuration.
/// </summary>
public string ConfigurationId { get; set; }

/// <summary>
/// Gets and sets the Bucket property.
/// </summary>
public S3BucketEntity Bucket { get; set; }

/// <summary>
/// Gets and sets the Object property.
/// </summary>
public S3ObjectEntity Object { get; set; }

/// <summary>
/// Gets and sets the S3SchemaVersion property.
/// </summary>
public string S3SchemaVersion { get; set; }
}

/// <summary>
/// The class holds the request parameters
/// </summary>
public class RequestParametersEntity
{
/// <summary>
/// Gets and sets the SourceIPAddress. This is the ip address where the request came from.
/// </summary>
public string SourceIPAddress { get; set; }
}

/// <summary>
/// This class holds the response elements.
/// </summary>

[DataContract]
public class ResponseElementsEntity
{
/// <summary>
/// Gets and sets the XAmzId2 Property. This is the Amazon S3 host that processed the request.
/// </summary>
[DataMember(Name = "x-amz-id-2", EmitDefaultValue = false)]
[System.Text.Json.Serialization.JsonPropertyName("x-amz-id-2")]
public string XAmzId2 { get; set; }

/// <summary>
/// Gets and sets the XAmzRequestId. This is the Amazon S3 generated request ID.
/// </summary>
[DataMember(Name = "x-amz-request-id", EmitDefaultValue = false)]
[System.Text.Json.Serialization.JsonPropertyName("x-amz-request-id")]
public string XAmzRequestId { get; set; }
}

/// <summary>
/// The class holds the glacier event data elements.
/// </summary>
public class S3GlacierEventDataEntity
{
/// <summary>
/// Gets and sets the RestoreEventData property.
/// </summary>
public S3RestoreEventDataEntity RestoreEventData { get; set; }
}

/// <summary>
/// The class holds the restore event data elements.
/// </summary>
public class S3RestoreEventDataEntity
{
/// <summary>
/// Gets and sets the LifecycleRestorationExpiryTime the time when the object restoration will be expired.
/// </summary>
public DateTime LifecycleRestorationExpiryTime { get; set; }

/// <summary>
/// Gets and sets the LifecycleRestoreStorageClass the source storage class for restore.
/// </summary>
public string LifecycleRestoreStorageClass { get; set; }
}

/// <summary>
/// The class holds the event notification.
/// </summary>
public class S3EventNotificationRecord
{
/// <summary>
/// Gets and sets the AwsRegion property.
/// </summary>
public string AwsRegion { get; set; }

/// <summary>
/// Gets and sets the EventName property. This identities what type of event occurred.
/// For example for an object just put in S3 this will be set to EventType.ObjectCreatedPut.
/// </summary>
public string EventName { get; set; }

/// <summary>
/// Gets and sets the EventSource property.
/// </summary>
public string EventSource { get; set; }

/// <summary>
/// Gets and sets the EventTime property. The time when S3 finished processing the request.
/// </summary>
public DateTime EventTime { get; set; }

/// <summary>
/// Gets and sets the EventVersion property.
/// </summary>
public string EventVersion { get; set; }

/// <summary>
/// Gets and sets the RequestParameters property.
/// </summary>
public RequestParametersEntity RequestParameters { get; set; }

/// <summary>
/// Gets and sets the ResponseElements property.
/// </summary>
public ResponseElementsEntity ResponseElements { get; set; }

/// <summary>
/// Gets and sets the S3 property.
/// </summary>
public S3Entity S3 { get; set; }

/// <summary>
/// Gets and sets the UserIdentity property.
/// </summary>
public UserIdentityEntity UserIdentity { get; set; }

/// <summary>
/// Get and sets the GlacierEventData property.
/// </summary>
public S3GlacierEventDataEntity GlacierEventData { get; set; }
}
}
}