Re: [boto-users] create a bucket including the current date on the name

182 views
Skip to first unread message

Nathan Hoover

unread,
Apr 19, 2013, 1:44:34 AM4/19/13
to boto-...@googlegroups.com, boto-...@googlegroups.com
The error is pretty clear. You're trying to pass the module datetime as the parameter rather than an instance thereof. Try using str(datetime.utcnow()) on the line starting with date =. You should probably also be formatting the date to your own preference, since I'm not sure that all the characters returned by utcnow() will be valid for a bucket name. Also, do keep in mind that there is a limit of 100 buckets per account. 

Nathan

Please excuse typos or brevity; sent from my mobile device.

On Apr 18, 2013, at 17:52, Netflix Boundaries <netflix.b...@gmail.com> wrote:

Hi 

I'm trying to create a bucket. The name of the bucket should include the current date.

Not sure how to execute this.

______

#!/usr/bin/env python
# encoding: utf-8

from boto.s3.connection import S3Connection
import datetime

aws_key = 'KEY'
aws_secret_key =  'SECRET'
conn = S3Connection(aws_key, aws_secret_key)
date = datetime
bucket_name = date
bucket = conn.create_bucket(bucket_name)



___________
The output is :

Traceback (most recent call last):
  File "./bucketcreation.py", line 12, in <module>
    bucket = conn.create_bucket(bucket_name)
  File "/usr/lib/python2.7/dist-packages/boto/s3/connection.py", line 400, in create_bucket
    check_lowercase_bucketname(bucket_name)
  File "/usr/lib/python2.7/dist-packages/boto/s3/connection.py", line 53, in check_lowercase_bucketname
    if not (n + 'a').islower():
TypeError: unsupported operand type(s) for +: 'module' and 'str'



Any thoughts?


--
You received this message because you are subscribed to the Google Groups "boto-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to boto-users+...@googlegroups.com.
To post to this group, send email to boto-...@googlegroups.com.
Visit this group at http://groups.google.com/group/boto-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Netflix Boundaries

unread,
Apr 19, 2013, 3:59:53 AM4/19/13
to boto-...@googlegroups.com
Thanks Nathan

Have modified to this:


#!/usr/bin/env python
# encoding: utf-8

from boto.s3.connection import S3Connection
import datetime

aws_key = 'KEY'
aws_secret_key =  'SECRET'
conn = S3Connection(aws_key, aws_secret_key)
date = str(datetime.utcnow()
bucket_name = date
bucket = conn.create_bucket(bucket_name)


____

And now I'm getting this:


AttributeError: 'module' object has no attribute 'utcnow'



Please adivse.

Adrian Klaver

unread,
Apr 19, 2013, 9:30:25 AM4/19/13
to boto-...@googlegroups.com, Netflix Boundaries
On 04/19/2013 12:59 AM, Netflix Boundaries wrote:
> Thanks Nathan
>
> Have modified to this:
>
>
> #!/usr/bin/env python
> # encoding: utf-8
>
> from boto.s3.connection import S3Connection
> import datetime
>
> aws_key = 'KEY'
> aws_secret_key = 'SECRET'
> conn = S3Connection(aws_key, aws_secret_key)
> date = str(datetime.utcnow()
> bucket_name = date
> bucket = conn.create_bucket(bucket_name)
>
>
> ____
>
> And now I'm getting this:
>
>
> AttributeError: 'module' object has no attribute 'utcnow'
>
>
>
> Please adivse.
>

It might be worth it to spend some time here:

http://docs.python.org/2/library/datetime.html#module-datetime

In the meantime either:

from datetime import datetime
datetime.utcnow()

or

import datetime
datetime.datetime.utcnow()

--
Adrian Klaver
adrian...@gmail.com

Netflix Boundaries

unread,
Apr 19, 2013, 4:10:30 PM4/19/13
to boto-...@googlegroups.com
Hello Nathan and Adrian

Even though I'm not a programmer or python-knowledged guy, your guidance was very helpful. Thanks for the reference.

To accomplish the objective is very important the following before proceeding:


Bucket names should not contain upper case letters
Bucket names should not contain underscores (_)
Bucket names should not end with a dash
Bucket names should be between 3 and 63 characters long
Bucket names cannot contain dashes next to periods (e.g., "my-.bucket.com" and "my.-bucket" are invalid)
Bucket names cannot contain periods

Below what worked for me:


#!/usr/bin/env python
# encoding: utf-8

from boto.s3.connection import S3Connection
from time import strftime
aws_key = ''
aws_secret_key =  ''
conn = S3Connection(aws_key, aws_secret_key)
bucket_creation_date_time = strftime("%m%d%y--%H%M%S")
bucket = conn.create_bucket('bucketname--' + bucket_creation_date_time)



Now, I would like to avoid using the AWS keys on the script. Will make some research.


Thanks.


On Thursday, April 18, 2013 8:52:42 PM UTC-4, Netflix Boundaries wrote:
Hi 

I'm trying to create a bucket. The name of the bucket should include the current date.

Not sure how to execute this.

______

#!/usr/bin/env python
# encoding: utf-8

from boto.s3.connection import S3Connection
import datetime

aws_key = 'KEY'
aws_secret_key =  'SECRET'
conn = S3Connection(aws_key, aws_secret_key)
date = datetime
bucket_name = date
bucket = conn.create_bucket(bucket_name)

Adrian Klaver

unread,
Apr 19, 2013, 5:16:57 PM4/19/13
to boto-...@googlegroups.com, Netflix Boundaries
On 04/19/2013 01:10 PM, Netflix Boundaries wrote:
> Hello Nathan and Adrian
>
> Even though I'm not a programmer or python-knowledged guy, your guidance
> was very helpful. Thanks for the reference.
>
> To accomplish the objective is very important the following before
> proceeding:
>
>
> Bucket names should not contain upper case letters
> Bucket names should not contain underscores (_)
> Bucket names should not end with a dash
> Bucket names should be between 3 and 63 characters long
> Bucket names cannot contain dashes next to periods (e.g.,
> "my-.bucket.com" and "my.-bucket" are invalid)
> Bucket names cannot contain periods
>
> Below what worked for me:
>
>
> #!/usr/bin/env python
> # encoding: utf-8
>
> from boto.s3.connection import S3Connection
> from time import strftime
> aws_key = ''
> aws_secret_key = ''
> conn = S3Connection(aws_key, aws_secret_key)
> bucket_creation_date_time = strftime("%m%d%y--%H%M%S")
> bucket = conn.create_bucket('bucketname--' + bucket_creation_date_time)
>

Again, remember there is a limit of 100 buckets per account. Within a
bucket you can have unlimited objects:

http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
>
>
> Now, I would like to avoid using the AWS keys on the script. Will make
> some research.

https://code.google.com/p/boto/wiki/BotoConfig

>
>
> Thanks.
>


--
Adrian Klaver
adrian...@gmail.com

steve

unread,
Apr 19, 2013, 6:31:59 AM4/19/13
to boto-...@googlegroups.com
Hi,

On Friday 19 April 2013 01:29 PM, Netflix Boundaries wrote:
> Thanks Nathan
>
> Have modified to this:
>
>
> #!/usr/bin/env python
> # encoding: utf-8
>
> from boto.s3.connection import S3Connection
> import datetime
>
> aws_key = 'KEY'
> aws_secret_key = 'SECRET'
> conn = S3Connection(aws_key, aws_secret_key)
> date = str(datetime.utcnow()
> bucket_name = date
> bucket = conn.create_bucket(bucket_name)
>
>
> ____
>
> And now I'm getting this:
>
>
> AttributeError: 'module' object has no attribute 'utcnow'
>

The problem here is that you've imported the 'datetime' module instead of the
'datetime' object within the module (which is what Nathan meant). So, change:

import datetime
to
from datetime import datetime

btw, as an aside, it might be advantageous to play around with python and the
standard library itself a bit before trying out stuff with boto, else you'll
keep hitting issues like these which aren't exactly boto related.

hth,
cheers,
- steve

>
[...snip...]
Reply all
Reply to author
Forward
0 new messages