seram
New Creator

Need to connect to aws s3 and create a folder

Below is my code which I have used for connecting to aws s3 and creating a folder through crownpeak.

<%@ Import Namespace="Amazon" %>
<%@ Import Namespace="Amazon.S3" %>
<%@ Import Namespace="Amazon.S3.Model" %>

 

string folderPath = "/myfolder/customer/us/en/test_aws/";
string bucketName = "Test_my.com";
string awsAccessKey = "AKIA----------------------------------------";
string awsSecretKey = "4pCY-------------------------------------------bXT";

IAmazonS3 client = new AmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.USEast1);
PutObjectRequest request = new PutObjectRequest()
{
BucketName = bucketName,
Key = folderPath
};
PutObjectResponse response = client.PutObject(request);

-----------------------------------------------------------------------------------------------------------------------------------

The code dosen't work as I am not able to refer  the aws libraries  in crownpeak. I have tried adding the libraries using Visual Studio and it works while coding but it throws error "name space  could not be found" when i tried to save the code changes. Please let me know how to add or use the aws libraries in crownpeak.

0 Kudos
1 Reply
MarcusEdwards
Crownpeak (Retired)

This is correct behaviour -- you cannot provide third-party libraries that run in the CMS context. DXM is a SaaS product so all CMS template code runs remotely in the service infrastructure. There are significant security and quality of service risks in allowing developers to upload and run any code they wanted inside the service.

However, if we look at the specifics of AWS S3, you will notice that you cannot create "folders" in S3 per se -- you can use a convention that assets with a shared prefix can be used to group files and give the effect of folders.

In your case, you don't need to create the folders programmatically. If you have publishing packages in the CMS set up to publish to AWS S3, the folder structure in the CMS will be part of the filename and S3 will interpret the "path" elements of the filename as if they were folders. Note: you can control the filenames for assets directly through the filename.aspx and assetfilename.aspx handlers.

For example, if you have a folder structure in the CMS like this:

/site-root
  /en
    /articles
      Article One

The resulting filename will be something like:

/en/articles/article-one

and that will be the filename the asset is published to S3 with.

0 Kudos