• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Programming Amazon Web Services for Beginners (1)

on

  • 10,268 views

 

Statistics

Views

Total Views
10,268
Views on SlideShare
10,098
Embed Views
170

Actions

Likes
3
Downloads
159
Comments
0

6 Embeds 170

http://krugerdavid.com 61
http://krugerdavid.blogspot.com 53
http://blog.krugerdavid.com 31
http://localhost:8888 19
http://feeds.feedburner.com 4
http://localhost 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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 virtualhosted-style request (e.g., http://yourbucket.s3.amazonaws.com/yourobject)If you create a bucket using , you must follow the DNSguidelines.If you create a bucket using , applications that access yourbucket must be able to handle 307 redirects. For more information, see Request Redirectionand the REST API (p. 99).When using virtual hosted-style buckets with SSL, the SSL wild card certificate only matchesbuckets that do not contain periods. To work around this, use HTTP or write your owncertificate 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) Programming Amazon Web Services for Beginners (1) Presentation Transcript

  • ProgrammingAmazon Web Serviceswith Java & Eclipse- Short Tutorial -by Markus Klemsmarkus.klems@kit.edu
  • Amazon Web Service Developer Ecosystem
    FOCUS
    … and more.
  • 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
  • AWS Toolkit for Eclipse (1)
    Source: www.eclipse.org/downloads/, April 2010
  • AWS Toolkit for Eclipse (2)
    1) Go to “Help” > “Install New Software…”
    2) Enter http://aws.amazon.com/eclipse
    Source: aws.amazon.com/eclipse/, April 2010
  • AWS Toolkit for Eclipse (3)
    Source: aws.amazon.com/eclipse/, April 2010
  • AWS Toolkit for Eclipse (4)
    Source: aws.amazon.com/eclipse/, April 2010
  • CodingIntroduction
  • Amazon Web Service Credentials
  • Programming S3Introduction
  • Basic S3 Concepts
    Buckets
    HTTP PUT
    HTTP GET
    Objects
    HTTP PUT
    HTTP GET
  • 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)
  • 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");
  • 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
    <CreateBucketConfigurationxmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <LocationConstraint>EU</LocationConstraint>
    </CreateBucketConfiguration >
    CreateBucketRequest request = newCreateBucketRequest("eorg-exercise2");
    request.setRegion("EU");
    s3.createBucket(request);
  • Operations on Buckets: PUT (3)
    Set Access Control
    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…
    String bucketName = "eorg-exercise3";
    CannedAccessControlListacl = CannedAccessControlList.PublicRead;
    s3.createBucket(bucketName);
    s3.setBucketAcl(bucketName, acl);
  • 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(newListObjectsRequest().withBucketName(bucketName));
    for (S3ObjectSummary s : list.getObjectSummaries()) {
    System.out.println(" - " + s.getKey() + “ (size = " + s.getSize() + ")");
    }
  • 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(newPutObjectRequest(bucketName, key, createSampleFile(“Program-AWS")));
  • Operations on S3 Objects: PUT (2)
    Object Versioning
    BucketVersioningConfigurationconfig = newBucketVersioningConfiguration();
    config.setStatus(BucketVersioningConfiguration.ENABLED);
    SetBucketVersioningConfigurationRequestconfigReq = newSetBucketVersioningConfigurationRequest(bucketName,config);
    s3.setBucketVersioningConfiguration(configReq);
    PutObjectResult result = s3.putObject(newPutObjectRequest(bucketName, key, createSampleFile("Program- AWS-2")));
    System.out.println("Version ID: "+result.getVersionId());
  • 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(newGetObjectRequest(bucketName, key));
    System.out.println("Content-Type: " + object.getObjectMetadata().getContentType());
    displayTextInputStream(object.getObjectContent());
  • 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.”
  • Note: Mediated Access with Signed URLs
    S3
    Gatekeeper
    2.) Retrieve S3 object
    1.) Get signed URL
    Cf. James Murty: “Programming Amazon Web Services”, fig. 4-2
  • Programming EC2Introduction
  • Basic EC2 Concepts
    EC2 Flow
    Amazon Machine Images (AMIs)
    Regions & Availability Zones
    Run EC2 Instances
    Terminate EC2 Instances
  • EC2 Flow
    Source: EC2 Developer Guide 2010-08-3
  • 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
  • Amazon Machine Images (2)
  • 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.”
  • Availability Zones
    “[F]ailurescan 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.”
  • Run EC2 Instances (1)
    ec2 = new AmazonEC2Client(credentials);
    RunInstancesRequestreq = newRunInstancesRequest();
    req.setImageId("ami-480df921");
    req.setInstanceType("t1.micro");
    req.setMinCount(1);
    req.setMaxCount(1);
    RunInstancesResult res = ec2.runInstances(req);
    System.out.println(res.toString());
  • 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

  • Run EC2 Instances (3)
    AWS Management Console
    Eclipse Management Console
  • 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);
  • Don’t forget to terminate…
    TerminateInstancesRequestreq = newTerminateInstancesRequest().withInstanceIds(id);
    ec2.terminateInstances(req);
  • 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