Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Store temp file in .net lambda and then publish to s3Bucket

I am generating a .csv file for further storing in a s3 bucket using .net c# Lambda function.

This is the process i follow:

  1. Generate the .csv and store it in /tmp/ folder of the lambda function execution.
    In this step im not sure if it is really saving the file in that path.

    MEDevel.com: Open-source for Healthcare and Education

    Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

    Visit Medevel

        //filepath = @"/tmp/test.csv"
        try
        {
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@filepath, true))
            {
    
                file.WriteLine(ID + "," + workItemType + "," + title + "," + assignedTo + "," + state + "," + iterationPath);                    
                Console.WriteLine("Successfully added");
            }
        }
        catch (Exception ex)
        {
            throw new ApplicationException(" somethings wrong: ", ex);
        }
    
  2. Upload the file to s3 bucket.

        try
        {
            await client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest
            {
                BucketName = "mys3bucket",
                Key = "test.csv",
                ContentType = @"/tmp/test.csv"
            });
        await Task.CompletedTask;
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception in PutS3Object:" + ex.Message);                ;
        }
    

In this last step i get this error message:

Exception in PutS3Object:The format of value ‘\tmp\test.csv’ is invalid.

What i am doing wrong?

>Solution :

You need to send the data to include in the csv file:

    await client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest
    {
        BucketName = "mys3bucket",
        Key = "test.csv",
        ContentBody = DATAINSTRINGFORMAT,
        ContentType = @"text/csv"
    });

or as filepath to send:

    await client.PutObjectAsync(new Amazon.S3.Model.PutObjectRequest
    {
        BucketName = "mys3bucket",
        Key = "test.csv",
        FilePath = FILEPATHONYOURTEMPFOLDER,
        ContentType = @"text/csv"
    });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading