title: AWS C# cant figure out how to upload zip stream to S3 bucket
body: <p>I am currently in the process of trying to put 3rd party API data into a S3 bucket via a C# AWS Lambda function. The data from the 3rd party comes in a zip file that I have been able to save locally fine so I am assuming that is working as I need it to. The next step is to upload this data to a S3 bucket but via a stream rather than saving the file locally and uploading etc.</p>
  
  <pre><code>public static async void PutObjectAsync()
      {
          try
          {
              using (var client = new AmazonS3Client(Amazon.RegionEndpoint.EUWest2))
              {
  
                  var ms = new MemoryStream();
                  GetStream().CopyTo(ms);    //GetStream() returns the api data stream (Stream object).
  
                  var request = new PutObjectRequest()
                  {
                      BucketName = "*BUCKETNAME*",
                      Key = "data.zip",
                      InputStream = ms
  
                  };
  
                  var response = await client.PutObjectAsync(request);                  
  
              }
          }
          catch (AmazonS3Exception e)
          {
              Console.WriteLine(
                      "Error encountered ***. Message:'{0}' when writing an object"
                      , e.Message);
          }
          catch (Exception e)
          {
              Console.WriteLine(
                  "Unknown encountered on server. Message:'{0}' when writing an object"
                  , e.Message);
          }
  
          Console.ReadKey();
      }
   }
  </code></pre>
  
  <p>I get a object reference not set to reference of an object error on the PutObjectAsync function call. I have inspected the request and the memory stream appears to be loaded as expected from the CopyTo method. I am aware that buckets have issues with files over 5MB but the zip file is a lot smaller than 5MB.</p>
  
  <p>This is my first lambda function so any advice would be welcomed. Thanks in advance.</p>