Monday, April 29, 2024
HomeGolangConvert this node js code to golang - Getting Assist

Convert this node js code to golang – Getting Assist


‘use strict’

const AWS = require(‘aws-sdk’)
AWS.config.replace({ area: course of.env.AWS_REGION })
const s3 = new AWS.S3()

// Change this worth to regulate the signed URL’s expiration
const URL_EXPIRATION_SECONDS = 300

// Predominant Lambda entry level
exports.handler = async (occasion) => {
return await getUploadURL(occasion)
}

const getUploadURL = async operate(occasion) {
const randomID = parseInt(Math.random() * 10000000)
const Key = ${randomID}.jpg

// Get signed URL from S3
const s3Params = {
Bucket: course of.env.UploadBucket,
Key,
Expires: URL_EXPIRATION_SECONDS,
ContentType: ‘picture/jpeg’,

// This ACL makes the uploaded object publicly readable. You have to additionally uncomment
// the additional permission for the Lambda operate within the SAM template.

// ACL: 'public-read'

}

console.log(‘Params: ‘, s3Params)
const uploadURL = await s3.getSignedUrlPromise(‘putObject’, s3Params)

return JSON.stringify({
uploadURL: uploadURL,
Key
})
}

Howdy, Abhishek Kumar Gupta, and welcome to the discussion board!

It’s unlikely that anybody on this website will translate your complete node program into Go and provides it to you. There are different internet sites the place you’ll be able to pay folks to try this for you, however the objective of the members on this website is to assist information you so you’ll be able to resolve the issue (largely) your self.

With that objective in thoughts, at the moment, my ideas to you’re:

  1. Learn the documentation for the AWS SDK for Go.
  2. Try the examples.
  3. When you have any particular questions (e.g.: “How do I arrange a Lambda entry level in Go?” or “How do I specify an S3 add timeout in Go?”, and so on.), be at liberty to ask them right here.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments