Skip to content

Commit 058c9c4

Browse files
committed
Delete file bug fix from bucket.
1 parent f34e262 commit 058c9c4

File tree

9 files changed

+238
-13
lines changed

9 files changed

+238
-13
lines changed

01-webotron/LICENSE.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
MIT License
2+
Copyright (c) 2020 ANKIT KUMAR SINGH
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
The above copyright notice and this permission notice shall be included in all
10+
copies or substantial portions of the Software.
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17+
SOFTWARE.

01-webotron/Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pylint = "*"
1010
pydocstyle = "*"
1111
pyflakes = "*"
1212
setuptools = "*"
13+
twine = "*"
1314

1415
[packages]
1516
boto3 = "*"

01-webotron/Pipfile.lock

Lines changed: 116 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

01-webotron/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Automating AWS with Python
2+
Repository for the A Cloud Guru course *Automating AWS with Python*
3+
4+
## 01-webotron
5+
6+
Webotron is a script that will sync a local directory to an s3 bucket, and optionally configure Route 53 and cloudfront as well.
7+
8+
## Features
9+
10+
Webotron currently has the following features:
11+
12+
- List bucket
13+
- List contents of a bucket
14+
- Create and set up bucket
15+
- Sync directory tree to bucket
16+
- Set AWS profile with --profile=<profile_name>
17+
- Configure route 53 domain
18+
- Configure Cloud Front distribution with SSL

01-webotron/setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Inside of setup.cfg
2+
[metadata]
3+
description-file = README.md

01-webotron/setup.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,32 @@
22

33
setup(
44
name='webotron-20',
5-
version='0.1',
5+
version='0.2',
66
author='Ankit K Singh',
77
author_email='[email protected]',
88
description='Webotron 20 is a tool to deploy static website to AWS.',
9-
license='GPLv3+',
9+
license='MIT',
1010
packages=['webotron'],
1111
url='https://github.com/erankitcs/automating-aws-with-python',
12+
download_url='https://github.com/erankitcs/automating-aws-with-python/archive/v0.1.tar.gz',
13+
keywords = ['AWS', 'BOTO3', 'S3Website','CloudFront'],
1214
install_requires=[
1315
'click',
1416
'boto3'
1517
],
1618
entry_points='''
1719
[console_scripts]
1820
webotron=webotron.webotron:cli
19-
'''
21+
''',
22+
classifiers=[
23+
'Development Status :: 3 - Alpha',
24+
'Intended Audience :: Developers',
25+
'Topic :: Software Development :: Build Tools',
26+
'License :: OSI Approved :: MIT License',
27+
'Programming Language :: Python :: 3',
28+
'Programming Language :: Python :: 3.4',
29+
'Programming Language :: Python :: 3.5',
30+
'Programming Language :: Python :: 3.6',
31+
'Programming Language :: Python :: 3.8',
32+
],
2033
)

01-webotron/webotron/bucket.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ def upload_file(self, bucket, path, key):
149149
if self.manifest.get(key, '') == etag:
150150
print("Skipping {}, etag match".format(key))
151151
return
152+
print(
153+
'File has been successfully added : {}'.format(key)
154+
)
152155
return bucket.upload_file(
153156
path,
154157
key,
@@ -166,7 +169,6 @@ def delete_files(self, bucket, objects):
166169
},
167170
RequestPayer='Webotron'
168171
)
169-
print(response)
170172
for item in response['Deleted']:
171173
print(
172174
'File has been successfully deleted : {}'.format(item['Key'])
@@ -207,7 +209,8 @@ def handle_bucket(directory_flist, bucket_keylist):
207209
if key not in directory_flist:
208210
key_dic = {'Key': key}
209211
files_delete.append(key_dic)
210-
self.delete_files(bucket, files_delete)
212+
if files_delete:
213+
self.delete_files(bucket, files_delete)
211214

212215
handle_directory(root)
213216
handle_bucket(self.file_list_source, self.manifest)

01-webotron/webotron/webotron.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def setup_bucket(bucket):
8181
def sync(pathname, bucket):
8282
"""Sync contents from Path to Bucket."""
8383
bucket_manager.sync(pathname, bucket)
84+
print('Sync is successful. Your bucket URL is:')
8485
print(bucket_manager.get_bucket_url(bucket_manager.s3.Bucket(bucket)))
8586

8687

@@ -118,7 +119,7 @@ def setup_cdn(domain, bucket):
118119
print("Waiting for distribution deployment...")
119120
dist_manager.await_deploy(dist)
120121
else:
121-
print("Distribution aleady exists. Creating Alias Record.")
122+
print("Distribution already exists. Creating Alias Record.")
122123

123124
zone = domain_manager.find_hosted_zones(domain) \
124125
or domain_manager.create_hosted_zone(domain)

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,63 @@ Webotron currently has the following features:
1616
- Set AWS profile with --profile=<profile_name>
1717
- Configure route 53 domain
1818
- Configure Cloud Front distribution with SSL
19+
20+
##Installation
21+
pip install webotron-20
22+
23+
##Using webotron-20
24+
25+
- Setup AWS profile. .AWS/config
26+
27+
- Use profile to use/access AWS resources.
28+
29+
- PS C:\Users\Rishu> webotron
30+
Usage: webotron [OPTIONS] COMMAND [ARGS]...
31+
32+
Webotron deploys websites to AWS.
33+
34+
Options:
35+
--profile TEXT Use a given AWS profile.
36+
--help Show this message and exit.
37+
38+
Commands:
39+
find-cert Find a certificate for given domain.
40+
list-bucket-objects List objects in s3 bucket.
41+
list-buckets List all s3 buckets.
42+
setup-bucket Create and configure s3 bucket for Static Website...
43+
setup-cdn To Setup a cloud frot for given domain and bucket.
44+
setup-domain Configure DOMAIN to point to BUCKET.
45+
sync Sync contents from Path to Bucket.
46+
- Examples
47+
PS C:\Users\Rishu> webotron --profile=pythonAutomation list-buckets
48+
s3.Bucket(name='kittentest.techenvision.net')
49+
PS C:\Users\Rishu> webotron --profile=pythonAutomation list-bucket-objects kittentest.techenvision.net
50+
s3.ObjectSummary(bucket_name='kittentest.techenvision.net', key='css/main.css')
51+
s3.ObjectSummary(bucket_name='kittentest.techenvision.net', key='images/Balinese-kitten1.jpg')
52+
s3.ObjectSummary(bucket_name='kittentest.techenvision.net', key='images/Maine_coon_kitten_roarie.jpg')
53+
s3.ObjectSummary(bucket_name='kittentest.techenvision.net', key='images/SFSPCA_Kitten.jpg')
54+
s3.ObjectSummary(bucket_name='kittentest.techenvision.net', key='index.html')
55+
56+
PS C:\Users\Rishu> webotron --profile=pythonAutomation sync "D:\Tech\Automate AWS with Python\code\automating-aws-with-python\01-webotron\kitten_web" kittentest.techenvision.net
57+
File has been successfully added : css/main.css
58+
File has been successfully added : images/Balinese-kitten1.jpg
59+
File has been successfully added : images/Maine_coon_kitten_roarie.jpg
60+
File has been successfully added : images/SFSPCA_Kitten.jpg
61+
File has been successfully added : index.html
62+
File has been successfully deleted : webotron.py
63+
File has been successfully deleted : certificate.py
64+
File has been successfully deleted : cdn.py
65+
File has been successfully deleted : domain.py
66+
File has been successfully deleted : __init__.py
67+
File has been successfully deleted : util.py
68+
File has been successfully deleted : bucket.py
69+
Sync is successful. Your bucket URL is:
70+
http://kittentest.techenvision.net.s3-website.us-east-2.amazonaws.com
71+
72+
PS C:\Users\Rishu> webotron --profile=pythonAutomation find-cert kittentest.techenvision.net
73+
{'CertificateArn': 'arn:aws:acm:us-east-1:637555073356:certificate/56b961ea-f789-42a1-97fa-8328ccaa4a77', 'DomainName': 'techenvision.net'}
74+
75+
PS C:\Users\Rishu> webotron --profile=pythonAutomation setup-cdn kittentest.techenvision.net kittentest.techenvision.net
76+
Distribution already exists. Creating Alias Record.
77+
Domain configured: https://kittentest.techenvision.net
78+
PS C:\Users\Rishu>

0 commit comments

Comments
 (0)