Docs Menu

Docs HomeAtlas App Services

AWS S3 Snippets [Deprecated]

On this page

  • Overview
  • Upload an Image to S3
  • Get an Image From S3

Important

Third Party Services & Push Notifications Deprecation

Third party services and push notifications in App Services have been deprecated in favor of creating HTTP endpoints that use external dependencies in functions.

Webhooks have been renamed to HTTPS Endpoints with no change in behavior. You should migrate existing Webhooks.

Existing services will continue to work until November 1, 2024.

Because third party services and push notifications are now deprecated, they have been removed by default from the App Services UI. If you need to manage an existing third party service or push notification, you can add the configurations back to the UI by doing the following:

  • In the left navigation, under the Manage section, click App Settings.

  • Enable the toggle switch next to Temporarily Re-Enable 3rd Party Services, and then save your changes.

The code snippets on this page demonstrate how to work with Amazon Simple Storage Service through the AWS Service. All of the snippets require an AWS Service interface with a configuration of AWS Service rules that allow the service actions used in the snippet. You can run these snippets yourself by copying this code into an Atlas Function.

If your app does not have an AWS Service interface, create one before using these snippets.

This Atlas Function uploads a Base64 encoded image to AWS S3 using the PutObject action.

exports = function(base64EncodedImage, bucket, fileName, fileType) {
// Convert the base64 encoded image string to a BSON Binary object
const binaryImageData = BSON.Binary.fromBase64(base64EncodedImage, 0);
// Instantiate an S3 service client
const s3Service = context.services.get('myS3Service').s3('us-east-1');
// Put the object to S3
return s3Service.PutObject({
'Bucket': bucket,
'Key': fileName,
'ContentType': fileType,
'Body': binaryImageData
})
.then(putObjectOutput => {
console.log(putObjectOutput);
// putObjectOutput: {
// ETag: <string>, // The object's S3 entity tag
// }
return putObjectOutput
})
.catch(console.error);
};
Parameter
Type
Description
base64EncodedImage
string
A Base64 encoded image. You can convert an image File to Base64 with the readAsDataURL method from the FileReader Web API.
bucket
string
The name of the S3 bucket that will hold the image.
fileName
string
The name of the image file, including its file extension.
fileType
string
The MIME Type of the image.

This Atlas Function retrieves an object from AWS S3 using the GetObject action.

exports = function(bucket, fileName) {
// Instantiate an S3 service client
const s3Service = context.services.get('myS3Service').s3('us-east-1');
// Get the object from S3
return s3Service.GetObject({
'Bucket': bucket,
'Key': fileName,
})
.then(getObjectOutput => {
console.log(getObjectOutput);
// {
// ETag: <string>, // The object's S3 entity tag
// Body: <binary>, // The object data
// ContentType: <string>, // The object's MIME type
// }
const base64EncodedImage = getObjectOutput.Body
return base64EncodedImage
})
.catch(console.error);
};
Parameter
Type
Description
bucket
string
The name of the S3 bucket that will hold the image.
fileName
string
The name of the image file, including its file extension.
←  GitHub Service [Deprecated]GitHub Snippets [Deprecated] →