Programming Amazon Web Services for Beginners (1)

15,612 views

Published on

Published in: Business, Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
15,612
On SlideShare
0
From Embeds
0
Number of Embeds
188
Actions
Shares
0
Downloads
264
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide
  • If you follow the DNS-compatible naming constraints you can use all S3 features because the rules restrict to names that are valid in the DNS naming system.

    If you follow less constrained naming rules, you cannot use all features: e.g. different availability zones (outside the US)

    Buckets with names containing uppercase characters are not accessible using the virtual
    hosted-style request (e.g., http://yourbucket.s3.amazonaws.com/yourobject)
    If you create a bucket using <CreateBucketConfiguration>, you must follow the DNS
    guidelines.
    If you create a bucket using <CreateBucketConfiguration>, applications that access your
    bucket must be able to handle 307 redirects. For more information, see Request Redirection
    and the REST API (p. 99).
    When using virtual hosted-style buckets with SSL, the SSL wild card certificate only matches
    buckets that do not contain periods. To work around this, use HTTP or write your own
    certificate verification logic.
  • Amazon EC2 provides multiple Regions so you can launch Amazon EC2 instances in locations that meet your requirements. For example, you might want to launch instances in Europe to be closer to your European customers or to meet legal requirements.
    Each Amazon EC2 Region is designed to be completely isolated from the other Amazon EC2 Regions. This achieves the greatest possible failure independence and stability, and it makes the locality of each EC2 resource unambiguous.
    To launch or work with instances, you must specify the correct Region URL endpoint. For example, to access the US-East Region (default), you make service calls to the ec2.us-east-1.amazonaws.com service endpoint. The following table lists the Regions and associated endpoints.
  • Amazon EC2 provides multiple Regions so you can launch Amazon EC2 instances in locations that meet your requirements. For example, you might want to launch instances in Europe to be closer to your European customers or to meet legal requirements.
    Each Amazon EC2 Region is designed to be completely isolated from the other Amazon EC2 Regions. This achieves the greatest possible failure independence and stability, and it makes the locality of each EC2 resource unambiguous.
    To launch or work with instances, you must specify the correct Region URL endpoint. For example, to access the US-East Region (default), you make service calls to the ec2.us-east-1.amazonaws.com service endpoint. The following table lists the Regions and associated endpoints.
  • Programming Amazon Web Services for Beginners (1)

    1. 1. 1 Programming Amazon Web Services with Java & Eclipse - Short Tutorial - by Markus Klems markus.klems@kit.edu
    2. 2. 2 Amazon Web Service Developer Ecosystem Java • AWS Java libraries • AWS toolkit for Eclipse • … Ruby • Ruby gems (RightScale, amazon-ec2, AWS::S3) • … PHP • AWS PHP libraries • Zend Web development framework supports S3, EC2 & SQS • … .NET • AWS SDK for .NET (libraries, Visual Studio templates) • Windows on EC2 • … FOCUS … and more.
    3. 3. 3 AWS Software Development with Java AWS Java libraries Jets3t (James Murty) Open-source Java toolkit and application suite for Amazon S3 and CloudFront http://bitbucket.org/jmurty/jets3t/wiki/Home Typica (D. Kavanagh, Xerox Corporation) Open-Source Java libraries for a broad variety of Amazon Web Services http://code.google.com/p/typica/ Amazon SDK for Java Open-source Java libraries for a broad variety of Amazon Web Services http://aws.amazon.com/sdkforjava/ AWS toolkit for Eclipse Eclipse Plug-in AWS perspective with views “EC2 Instances”, “EC2 AMIs”, et cetera AWS Project Wizard
    4. 4. 4 AWS Toolkit for Eclipse (1) Source:www.eclipse.org/downloads/,April2010
    5. 5. 5 AWS Toolkit for Eclipse (2) 1) Go to “Help” > “Install New Software…” 2) Enter http://aws.amazon.com/eclipse Source:aws.amazon.com/eclipse/,April2010
    6. 6. 6 AWS Toolkit for Eclipse (3) Source:aws.amazon.com/eclipse/,April2010
    7. 7. 7 AWS Toolkit for Eclipse (4) Source:aws.amazon.com/eclipse/,April2010
    8. 8. 8 Coding Introduction
    9. 9. 9 Amazon Web Service Credentials
    10. 10. 10 Programming S3 Introduction
    11. 11. 11 Basic S3 Concepts Buckets HTTP PUT HTTP GET Objects HTTP PUT HTTP GET
    12. 12. 12 S3 Buckets DNS-compatible bucket names Bucket names must be unique in the S3 universe Bucket names should not contain underscores (_) Bucket names should be between 3 and 63 characters long Bucket names should not end with a dash Bucket names cannot contain two, adjacent periods Bucket names cannot contain dashes next to periods (e.g., "my- .bucket.com" and "my.-bucket" are invalid)
    13. 13. 13 Operations on Buckets: PUT PUT: Create a new bucket PUT / HTTP/1.1 Host: eorg-exercise1.s3.amazonaws.com Content-Length: 0 Date: Wed, 27 Oct 2010 12:00:00 GMT Authorization: AWS 15B4D3461F177624206A:xQE0diMbLRepdf… s3.createBucket(“eorg-exercise1");
    14. 14. 14 Operations on Buckets: PUT (2) Set the Bucket Region PUT / HTTP/1.1 Host: eorg-exercise2.s3.amazonaws.com Date: Wed, 27 Oct 2010 12:00:00 GMT Authorization: AWS 15B4D3461F177624206A:xQE0diMbLRepdf3Y… Content-Type: text/plain Content-Length: 124 <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <LocationConstraint>EU</LocationConstraint> </CreateBucketConfiguration > CreateBucketRequest request = new CreateBucketRequest("eorg-exercise2"); request.setRegion("EU"); s3.createBucket(request);
    15. 15. 15 Operations on Buckets: PUT (3) Set Access Control String bucketName = "eorg-exercise3"; CannedAccessControlList acl = CannedAccessControlList.PublicRead; s3.createBucket(bucketName); s3.setBucketAcl(bucketName, acl); PUT / HTTP/1.1 Host: eorg-exercise3.s3.amazonaws.com Content-Length: 0 x-amz-acl: public-read Date: Wed, 27 Oct 2010 12:00:00 GMT Authorization: AWS 15B4D3461F177624206A:xQE0diMbLRep…
    16. 16. 16 Operations on Buckets: GET (1) Return all (up to 1000) of the objects in a bucket GET / HTTP/1.1 Host: eorg-exercise3.s3.amazonaws.com Date: Wed, 27 Oct 2010 12:00:00 GMT Authorization: AWS 15B4D3461F177624206A:xQE0diMbLRep… Content-Type: text/plain String bucketName = "eorg-exercise3"; ObjectListing list = s3.listObjects(new ListObjectsRequest().withBucketName(bucketName)); for (S3ObjectSummary s : list.getObjectSummaries()) { System.out.println(" - " + s.getKey() + “ (size = " + s.getSize() + ")"); }
    17. 17. 17 Operations on S3 Objects: PUT (1) PUT /isbn-12345 HTTP/1.1 Host: eorg-exercise3.s3.amazonaws.com Date: Wed, 27 Oct 2010 12:00:00 GMT Authorization: AWS 15B4D3461F177624206A:xQE0diMbLRep… Content-Type: text/plain Content-Length: 135 Content-MD5: JBVusP8u0QVhBvsvxNDthQ== […data…] String bucketName = "eorg-exercise3"; String key = "isbn-12345"; s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile(“Program-AWS")));
    18. 18. 18 Operations on S3 Objects: PUT (2) Object Versioning BucketVersioningConfiguration config = new BucketVersioningConfiguration(); config.setStatus(BucketVersioningConfiguration.ENABLED); SetBucketVersioningConfigurationRequest configReq = new SetBucketVersioningConfigurationRequest(bucketName, config); s3.setBucketVersioningConfiguration(configReq); PutObjectResult result = s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile("Program- AWS-2"))); System.out.println("Version ID: "+result.getVersionId());
    19. 19. 19 Operations on S3 Objects: GET GET /isbn-12345 HTTP/1.1 Host: eorg-exercise3.s3.amazonaws.com Date: Wed, 27 Oct 2010 12:00:00 GMT Authorization: AWS 02236Q3V0WHVSRW0EXG2:0RQf4/cR… String bucketName = "eorg-exercise3"; String key = "isbn-12345"; S3Object object = s3.getObject(new GetObjectRequest(bucketName, key)); System.out.println("Content-Type: " + object.getObjectMetadata().getContentType()); displayTextInputStream(object.getObjectContent());
    20. 20. 20 Note: Access Control Lists “Note: Bucket and object ACLs are completely independent; an object does not inherit the ACL from its bucket. For example, if you create a bucket and grant write access to another user, you will not be able to access the user's objects unless the user explicitly grants access. This also applies if you grant anonymous write access to a bucket. Only the user "anonymous" will be able to access objects the user created unless permission is explicitly granted to the bucket owner. Important: We highly recommend that you do not grant the anonymous group write access to your buckets as you will have no control over the objects others can store and their associated charges.”
    21. 21. 21 Note: Mediated Access with Signed URLs Gatekeeper 1.) Get signed URL S3 2.) Retrieve S3 object Cf. James Murty: “Programming Amazon Web Services”, fig. 4-2
    22. 22. 22 Programming EC2 Introduction
    23. 23. 23 Basic EC2 Concepts EC2 Flow Amazon Machine Images (AMIs) Regions & Availability Zones Run EC2 Instances Terminate EC2 Instances
    24. 24. 24 EC2 Flow Source: EC2 Developer Guide 2010-08-3
    25. 25. 25 Amazon Machine Images (AMIs) Amazon Machine Images (AMIs) are virtual machine images with a root device which is stored either in Amazon S3, or Amazon Elastic Block Store (EBS) Pre-configured public AMIs are provided by the AWS community
    26. 26. 26 Amazon Machine Images (2)
    27. 27. 27 Regions “Amazon EC2 provides multiple Regions so you can launch Amazon EC2 instances in locations that meet your requirements. Each Amazon EC2 Region is designed to be completely isolated from the other Amazon EC2 Regions. This achieves the greatest possible failure independence and stability, and it makes the locality of each EC2 resource unambiguous.”
    28. 28. 28 Availability Zones “[F]ailures can occur that affect the availability of instances that are in the same location. Although this is rare, if you host all your Amazon EC2 instances in a single location that is affected by such a failure, your instances will be unavailable. For example, if you have instances distributed across three Availability Zones and one of the instances fails, you can design your application so the instances in the remaining Availability Zones handle any requests.”
    29. 29. 29 Run EC2 Instances (1) ec2 = new AmazonEC2Client(credentials); RunInstancesRequest req = new RunInstancesRequest(); req.setImageId("ami-480df921"); req.setInstanceType("t1.micro"); req.setMinCount(1); req.setMaxCount(1); RunInstancesResult res = ec2.runInstances(req); System.out.println(res.toString());
    30. 30. 30 Run EC2 Instances (2) HTTP POST Request https://ec2.amazonaws.com/?Action=RunInstances &ImageId=ami-480df921 &MaxCount=1 &MinCount=1 &Placement.AvailabilityZone=eu-west-1b &SignatureMethod=HmacSHA256 & AWSAccessKeyId=123 …
    31. 31. 31 Run EC2 Instances (3) AWS Management Console Eclipse Management Console
    32. 32. 32 Run EC2 Instances (4) Run EC2 Instances in the EU Region ec2 = new AmazonEC2Client(credentials); ec2.setEndpoint("https://eu-west- 1.ec2.amazonaws.com"); ... Placement p = new Placement(); p.setAvailabilityZone("eu-west-1b"); req.setPlacement(p);
    33. 33. 33 Don’t forget to terminate… TerminateInstancesRequest req = new TerminateInstancesRequest().withInstanceIds(id); ec2.terminateInstances(req);
    34. 34. 34 References S3 Developer Guide 2006-03-01 S3 API Reference 2006-03-01 EC2 Developer Guide 2010-08-31 EC2 API Reference 2010-08-31

    ×