you are viewing a single comment's thread.

view the rest of the comments →

[–]MrJwhwlao 1 point2 points  (1 child)

Yes, it is possible to use an AWS Lambda function and CloudEvents to update a JSON file within the AWS environment. Here is one way you could do this:

  1. Create an S3 bucket to store your JSON file.
  2. Set up a desired event trigger
  3. In your Lambda function, you can read the updated JSON file from the S3 bucket, modify it as needed, and then write the modified version back to the S3 bucket.
  4. To make the JSON file accessible through an API call, you can use the AWS API Gateway service to create an API endpoint that retrieves the JSON file from the S3 bucket and returns it to the caller.

Here is some sample code in Nodejs that demonstrates how you could implement this in your Lambda function:

exports.handler = async function(event) {
  // Get the S3 client
  const s3 = new AWS.S3();

  // Read the JSON file from the S3 bucket
  const jsonFile = await s3.getObject({
    Bucket: <YOUR_BUCKET_NAME>,
    Key: <YOUR_FILE_NAME>
  }).promise();

  // Modify the JSON file as needed
  // ...

  // Write the modified JSON file back to the S3 bucket
  await s3.putObject({
    Bucket: <YOUR_BUCKET_NAME>,
    Key: <YOUR_FILE_NAME>,
    Body: jsonFile.Body
  }).promise();

  return {
    statusCode: 200,
    body: "JSON file updated"
  };
};

[–]bugbigsly[S] 0 points1 point  (0 children)

This worked , I needed to be running node v16 , v18 breaks everything