Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

269
Vistas
AWS Lambda C# Upload Object to S3

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?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

This is the helper function I use to put S3 objects to S3, from a C# lambda function (and it works). You might be able to use this as a starting point for yours.

Not sure why you are converting your string to bytes, and in C#/Lambda you need to use the PutObjectAsync method, not the PutObject method:

 public static async Task<bool> PutS3Object(string bucket, string key, string content)
        {
            try
            {
                using (var client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1))
                {
                    var request = new PutObjectRequest
                    {
                        BucketName = bucket,
                        Key = key,
                        ContentBody = content
                    };
                    var response = await client.PutObjectAsync(request);
                }
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in PutS3Object:" + ex.Message);
                return false;
            }
        }
about 4 years ago · Santiago Trujillo Denunciar

0

You should apply await with the Async

await client.PutObjectAsync(request);

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda