Home > > Newbie Follow-Alongs

Automatically push lander edits from Sublime Text to S3 (16)


04-03-2019 03:29 PM #1 192837465 (Member)
Automatically push lander edits from Sublime Text to S3

I'm following @vortex's (Amy's) 40-Day Tutorial and one of the sections is on editing and uploading your landers to an AWS S3 Bucket.

One option is to use CrossFTP as described in the tutorial Day 19-25: Fixing Up Landers.

Another option which is a bit quicker, is to automatically have Sublime sync your S3 bucket with your local files.

User @robertson talks about it a bit on this post. I have a background in coding and I'm going to use this thread to elaborate his method a bit further and make it more accessible.

Note: This guide uses Mac OS X + Amazon S3 + Sublime, but you can still make it work on Windows by tweaking some parts here and there.

Requirements

Pip - Pip is a python library manager that we'll use to install AWS's Command Line Interface (CLI). Please make sure you have PIP installed on your machine before moving forward.

How to install Pip on Windows, Mac OS & Linux

Verify that PIP is installed by opening your terminal (mac) OR Git Bash / any other unix terminal (Windows) and typing

Code:
pip --version


You should see something like
Code:
 pip 18.0 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
in response.


Attachment 20970


Steps

1. In your terminal, type
Code:
pip install awscli
If pip was set up properly, it should install the AWS CLI without any problems. To make sure it is installed properly, type
Code:
aws
into your command line. You should see something similar to this:



Attachment 20971
Code:
 
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]To see help text, you can run:
Code:
aws help
aws <command> help
aws <command> <subcommand> help
aws: error: the following arguments are required: command


2. Once that has finished, we have to configure the aws cli by adding our Access Key and Access Key Secret.

Go into your AWS account, click on your name in the top right, and click "My Security Credentials".

Open the "Access Keys" tab and click "Create New Access Key"

Click "Show Access Key" on the following popup window.

You will see two separate keys. Keep this tab open. Note that this will be the only time you can see these keys, so it's recommended downloading it and storing it in a safe place for future reference.


Attachment 20972

Go back to your terminal and type
Code:
aws configure


It will prompt you to enter some information. Copy and paste your Access key and Secret Access Key, and then click enter for the next fields.

Your AWS account should now be linked to your terminal / computer.

3. Modify Sublime Text's Build System
In your terminal, you're going to want to navigate to /Users/YourName/Library/Application Support/Sublime Text 3/Packages/User

Note: Since there are spaces in the directory names, it might be a bit tricky to navigate there.
Note: For windows users, this directory might be somewhere different.

To do this, you can type
Code:
cd /Users/anthony/Library/Application\ Support/Sublime\ Text\ 3/Packages/User
. I've added in some back \'s to negate the spaces in the directory name.
Make sure you replace "Anthony" with the name you have on your Mac.

Once in this directory, we need to create a file called
Code:
s3up.sublime-build
You can either use a file editor, or you can create it in terminal.

Note: Make sure the file is named s3up.sublime-build without any extension at the end. That should be the full file name.

Now add the following lines of code inside of the file:

Code:
{
"cmd": ["aws", "s3", "sync", "/Users/yourName/landers", "s3://your-bucket-name"]
}
Make sure you change the directory and bucket url accordingly.

For example, I have all my landers in the following directory:
Code:
/Users/anthony/Desktop/Business/AFFILIATE/s3
so that's what I would put as my directory instead of
/Users/yourName/landers .

My bucket name is "mywebsite.com" so the S3 url parameter would be "s3://mywebsite.com".

Once you've added that, save the file.

4. Making sure it works

Open the directory with your landers in Sublime text.

Mine looks like this:
Attachment 20973



Let's create a new file called "test.txt", add some random stuff inside of it, and save it.
Attachment 20974


Now all we have to do to push it to our S3 is run our Sublime Text's "Build".

To do that you can press ⌘ + B
or
manually by going to Tools > Build

A terminal at the bottom of your Sublime Text should show up saying the following:

Attachment 20975



Now go to your S3 Bucket and verify that it worked!

Attachment 20976


And you're done!

Important to note
This process pushes any modified files and new files to your s3 from
your computer.





I hope this helped anyone at all, and I hope it wasn't too hard to read - this is the first tutorial I've ever posted so the formatting and grammar sucks.

- Anthony


04-13-2019 06:05 AM #2 vortex (Senior Moderator)

@0192837465 Thanks very much for posting this in a new thread! I'm very surprised the thread hasn't received thanks up to now!

I'm linking from the tutorial to this thread - your detailed instructions (which have no doubt taken you a lot of time to write) will help a lot of other newbie members.

Thanks a million times over for your post!



Amy


08-14-2019 04:01 AM #3 tjeezy (Member)

@0192837465 - This is really slick, thanks for taking the time to walk us through it.

However, I am using Windows and am struggling to get the text.txt file to push to S3.

My question is: When we add the below "cmd" code "inside" of s3up.sublime-build, where is this actually done? I've replaced the directory and URL and input the code into the file in Sublime text editor, but I am getting the following error when trying to push the test.txt file to S3: "No build system"

{
"cmd": ["aws", "s3", "sync", "/Users/yourName/landers", "s3://your-bucket-name"]
}

Curious if you have any insight or if there are other windows users out there who've been able to get this to work. Thanks!




08-30-2019 11:58 AM #4 mahakal (Member)

Awesome @0192837465 thanks mate


08-31-2019 06:26 PM #5 tjeezy (Member)

In case any windows users are having issues with the build-system like I was, I added "shell: true" to the code and was able to get it working. The code looks like this:

{
"shell": true,
"cmd": ["aws", "s3", "sync", "/Users/yourName/landers", "s3://your-bucket-name"]
}

Thanks @0192837465!


12-12-2019 07:44 AM #6 dariavelvet (Member)

Thank you guys for that valuable method. I use it on Windows 10, it works!

Just one quick question, since I'm not a coder. How can I implement this method for different buckets? How the code will look like?


12-16-2019 04:04 AM #7 vortex (Senior Moderator)

Quote Originally Posted by dariavelvet View Post
Thank you guys for that valuable method. I use it on Windows 10, it works!

Just one quick question, since I'm not a coder. How can I implement this method for different buckets? How the code will look like?
It looks like a simple replacement:

-replace "/Users/yourName/landers" with your own file path
-replace "your-bucket-name" with your bucket name



Amy


12-23-2019 03:13 AM #8 vortex (Senior Moderator)

NOTE: @mrhaste has shared further tips on executing the method in the first post:

https://stmforum.com/forum/showthrea...l=1#post385771

Hi,

I followed @0192837465 guide and found small hiccups in Windows 10 not able to find the "python", "aws" executable in Windows command prompt.
I was able to solve it doing the following:

1. Instead of using the full package from Python's website. Use the one in Microsoft store instead. It will add proper "PATH" to the command prompt.
2. Follow Amazon's guide here: https://docs.aws.amazon.com/cli/late...ll-windows-pip
to add aws command to Window's "PATH"

Cheers,
Pon
Hope this helps someone!



Amy


03-12-2020 02:59 AM #9 mikoletz (Member)

Thank you for this quick sublime guide! Uploading is super easy now. Just to add, if you are having problem on locating your build package on your terminal, you can just simply do it in sublime by clicking tools --> Build System --> New Build system and paste the code above and save it as s3up.sublime-build and it should work the same.


04-26-2020 11:22 AM #10 nitrousoxide (Member)

Quote Originally Posted by tjeezy View Post
In case any windows users are having issues with the build-system like I was, I added "shell: true" to the code and was able to get it working. The code looks like this:

{
"shell": true,
"cmd": ["aws", "s3", "sync", "/Users/yourName/landers", "s3://your-bucket-name"]
}

Thanks @0192837465!
Interesting, I'm on Windows and I added

"shell": true,

Still says 'no build system'


04-26-2020 07:48 PM #11 mattbucks (Member)

Full disclosure: I know close to zero coding so I apologize if I am missing something rudimentary here.

I'm having issues installing awscli. I have PIP installed and confirmed it by typing pip -- version. I got the following:

pip 20.1b1 from /Library/Python/2.7/site-packages/pip-20.1b1-py2.7.egg/pip (python 2.7)

I then tried installing awscli by typing the following: pip install awscli

Linked here a screenshot of the result (image is in Google drive because was having issues uploading here - tech problems man lol).

When I type aws, it says "Command Not Found". Any insight on where I may be going wrong? I tried updating Python from 2.7 to the latest version and still have had no luck. I hope this explanation made some sense Thanks in advance!


04-27-2020 01:07 AM #12 nitrousoxide (Member)

Quote Originally Posted by mattbucks View Post
Full disclosure: I know close to zero coding so I apologize if I am missing something rudimentary here.

I'm having issues installing awscli. I have PIP installed and confirmed it by typing pip -- version. I got the following:

pip 20.1b1 from /Library/Python/2.7/site-packages/pip-20.1b1-py2.7.egg/pip (python 2.7)

I then tried installing awscli by typing the following: pip install awscli

Linked here a screenshot of the result (image is in Google drive because was having issues uploading here - tech problems man lol).

When I type aws, it says "Command Not Found". Any insight on where I may be going wrong? I tried updating Python from 2.7 to the latest version and still have had no luck. I hope this explanation made some sense Thanks in advance!
Not sure if this helps, but I was able to get awscli installed but I went out of my way to download Python v 3.x

That could solve your issue?

Are you on Windows?


04-27-2020 02:32 AM #13 affpayinggao (Veteran Member)

What a share. Thank you


06-09-2020 01:19 AM #14 brunno (Member)
oops, I messed up!

I can't seem to get step 3 to work. I accidentally added the lines of code into s3up.sublime-build without editing them first. I only realised it once I tried to see if everything was working on sublime text and retraced my steps. So then I wasn't sure what to do so I tried to redo step 3 but that didn't work either.

I used the "nano s3up.sublime-build" command to create the file in terminal.
https://imgur.com/ouGyIwb
when I tried it the second time around I was hoping it would lead me to the file I had created previously but instead there was no text.
https://imgur.com/4oLA2e2
So I tried putting in what I believe to be the "correct" lines of code.
I saved the lines and then terminated nano.

However its still not working.
https://imgur.com/bxh7hem

Am I making a mistake somewhere or is it just not working because I filled in the wrong code the first time around? If so what can I do? do I need to delete the "wrong" file I created on terminal, or should re-doing step 3 correctly solve things? I have no experience with terminal so if you can dumb your explanation down for me that would be great! apologies for the links, I tried inserting pictures but i couldn't get it to work either. I guess its just one of those days....


01-09-2021 03:39 AM #15 vallem (Member)

What a headache it was to do this on my laptop!! I was having trouble installing PIP and AWS CLI.

In my case it didn't work because I had the old version of Python (Python 2.7 > which is installed by default on the mac OS > this version stopped working as of this january 2021), and the AWS code from this guide was outdated... When it comes to technology, better to always have everything up to date.

After hours and hours of trial and error, asking Google and a lot of breathing, it finally worked!!

Just in case someone has the same problem I had, this is how I made it work :


It was ridiculously simple


1) Download and install the latest version of Python >> https://www.python.org/downloads/


2) Download and Install Pip3 (latest one) >> Open the Terminal and use the following command to download pip directly

Code:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Execute the downloaded file using below command


Code:
python3 get-pip.py
Check the installation

Code:
pip3 --version
You will see something like this >>

"pip 20.2.3 from Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9)"


3) Execute the latest version of the AWS CLI using following command block


Code:
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
Check the installation

Code:
aws --version
You will see something like this >> "aws-cli/2.1.17 Python/3.7.4 Darwin/20.2.0 exe/x86_64 prompt/off"

Voila!!! See? version AWS CLI 2.1 using Python3


Now I could finally continue with the rest of the steps. BTW thank you @0192837465 for the guide!!


01-09-2021 02:00 PM #16 vortex (Senior Moderator)

@vallem Thank you so much for taking the time to figure this out and then share all the steps!! Much appreciated!


Amy


Sent from my iPhone using STM Forums


Home > > Newbie Follow-Alongs