I have a Lambda function written in C# that is unsuccessfully attempting to upload an object to an S3 bucket. For testing purposes, I am converting the input string to a byte array and using that as the object contents. My handler function is defined below:
public void FunctionHandler(string input, ILambdaContext context)
{
IAmazonS3 client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1);
byte[] bytes = new byte[input.Length * sizeof(char)];
Buffer.BlockCopy(input.ToCharArray(), 0, bytes, 0, bytes.Length);
using (MemoryStream ms = new MemoryStream())
{
foreach (Byte b in bytes)
{
ms.WriteByte(b);
}
PutObjectRequest request = new PutObjectRequest()
{
BucketName = "BUCKET_NAME",
Key = "OBJECT_KEY",
InputStream = ms
};
client.PutObjectAsync(request);
}
}
The function runs without error, but the object is not written to S3. I feel that it might have something to do with the PutObjectAsync method, but I'm not positive. The IAmazonS3 interface includes a PutObject method, but when attempting to use that method I receive the following error:
'IAmazonS3' does not contain a definition for 'PutObject'
What is the best way to upload an object to an S3 bucket in a C# Lambda function?