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.
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:
The resulting filename will be something like:
and that will be the filename the asset is published to S3 with.