Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 9091e94

Browse files
author
Paul Cornell
committed
Fixed AWS SDK examples.
1 parent 5f56b56 commit 9091e94

7 files changed

Lines changed: 70 additions & 27 deletions

File tree

doc_source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
# The link to the top of the doc source tree on GitHub. This allows generation
4747
# of per-page "Edit on GitHub" links.
48-
#github_doc_url = 'https://github.com/awsdocs/aws-cloud9-ug/tree/master/doc_source'
48+
github_doc_url = 'https://github.com/awsdocs/aws-cloud9-user-guide/tree/master/doc_source'
4949

5050
# This allows the "Feedback" button to create a new issue on GitHub.
5151
#doc_feedback_url = 'https://github.com/awsdocs/aws-java-developer-guide/issues/new'

doc_source/sample-cplusplus.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
eifjccfvciuhdbchfggrcldbkkrhlrndvheelieckhfr
12
.. Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
23
34
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0
@@ -184,7 +185,8 @@ you must set up credentials management in your |env|. The |sdk-cpp| needs these
184185
185186
.. topic:: To build the |sdk-cpp|
186187

187-
.. note:: This step could take up to one or more hours to complete, depending on the computing resources available to your |EC2| instance or your own server.
188+
.. note:: This step could take up to one or more hours to complete, depending on the computing resources available to your |EC2| instance or your own server and
189+
how much of the |sdk-cpp| you choose to build.
188190

189191
#. Create a folder to build the |sdk-cpp| into.
190192

@@ -204,6 +206,12 @@ you must set up credentials management in your |env|. The |sdk-cpp| needs these
204206
205207
cmake3 ../aws-sdk-cpp-master
206208
209+
.. note:: To build only the |S3| portion of the |sdk-cpp| and its dependencies, run this command instead:
210+
211+
.. code-block:: sh
212+
213+
cmake3 ../aws-sdk-cpp-master -DBUILD_ONLY="s3"
214+
207215
#. Build the |sdk-cpp| into this folder.
208216

209217
.. code-block:: sh
@@ -234,7 +242,7 @@ Step 5: Add AWS SDK Code
234242
In this step, you add some more code, this time to interact with |s3| to create a bucket, list your available buckets, and then delete the bucket you just created. You
235243
will run this code later.
236244

237-
#. In the |AC9IDE|, create a file with this content, and save the file with the name :file:`s3.cpp` at the root (:file:`/`) of your |env|.
245+
#. In the |AC9IDE|, create a file with this content, and save the file with the name :file:`s3-demo.cpp` at the root (:file:`/`) of your |env|.
238246

239247
.. code-block:: cpp
240248
@@ -391,7 +399,7 @@ Step 6: Build and Run the AWS SDK Code
391399

392400
.. code-block:: sh
393401
394-
cmake -Daws-sdk-cpp_DIR=sdk_build .
402+
cmake3 -Daws-sdk-cpp_DIR=sdk_build .
395403
396404
#. Build your source code.
397405

doc_source/sample-go.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ you must set up credentials management in your |env|. The |sdk-go| needs these c
180180
. ~/.bashrc
181181
182182
#. Confirm that the :code:`GOPATH` environment variable is successfully set by running the :command:`echo
183-
$GOPATH` command. If successful, :code:`/home/ec2-user/environment/go` should be output.
183+
$GOPATH` command. If successful, :code:`/home/ec2-user/environment/go` should be output.
184184

185185
.. topic:: To install the |sdk-go|
186186

@@ -229,13 +229,13 @@ In the |AC9IDE|, create a file with this content, and save the file with the nam
229229
sess := session.Must(session.NewSessionWithOptions(session.Options{
230230
SharedConfigState: session.SharedConfigEnable,
231231
}))
232-
232+
region := "YOUR_REGION"
233233
svc := s3.New(sess, &aws.Config{
234-
Region: aws.String("YOUR_REGION"),
234+
Region: aws.String(region),
235235
})
236236
237237
listMyBuckets(svc)
238-
createMyBucket(svc, os.Args[1])
238+
createMyBucket(svc, os.Args[1], region)
239239
listMyBuckets(svc)
240240
deleteMyBucket(svc, os.Args[1])
241241
listMyBuckets(svc)
@@ -259,12 +259,15 @@ In the |AC9IDE|, create a file with this content, and save the file with the nam
259259
}
260260
261261
// Create a bucket in this AWS Region.
262-
func createMyBucket(svc *s3.S3, bucketName string) {
262+
func createMyBucket(svc *s3.S3, bucketName string, region string) {
263263
fmt.Printf("\nCreating a new bucket named '" + bucketName + "'...\n\n")
264264
265265
_, err := svc.CreateBucket(&s3.CreateBucketInput{
266-
Bucket: aws.String(bucketName),
267-
})
266+
Bucket: aws.String(bucketName),
267+
CreateBucketConfiguration: &s3.CreateBucketConfiguration{
268+
LocationConstraint: aws.String(region),
269+
},
270+
})
268271
269272
if err != nil {
270273
exitErrorf("Unable to create bucket, %v", err)

doc_source/sample-nodejs.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,22 @@ In the |AC9IDE|, create a file with this content, and save the file with the nam
164164
165165
var AWS = require('aws-sdk'); // To set the AWS credentials and region.
166166
var async = require('async'); // To call AWS operations asynchronously.
167+
var region = 'YOUR_REGION';
167168
168169
AWS.config.update({
169-
region: 'YOUR_REGION'
170+
region: region
170171
});
171172
172173
var s3 = new AWS.S3({apiVersion: '2006-03-01'});
173174
174175
var bucket_name = process.argv[2];
175-
var params = {Bucket: bucket_name};
176+
var create_bucket_params = {
177+
Bucket: bucket_name,
178+
CreateBucketConfiguration: {
179+
LocationConstraint: region
180+
}
181+
};
182+
var delete_bucket_params = {Bucket: bucket_name};
176183
177184
// List all of your available buckets in this AWS Region.
178185
function listMyBuckets(callback) {
@@ -195,7 +202,7 @@ In the |AC9IDE|, create a file with this content, and save the file with the nam
195202
function createMyBucket(callback) {
196203
console.log('\nCreating a bucket named ' + bucket_name + '...\n');
197204
198-
s3.createBucket(params, function(err, data) {
205+
s3.createBucket(create_bucket_params, function(err, data) {
199206
if (err) {
200207
console.log(err.code + ": " + err.message);
201208
}
@@ -208,7 +215,7 @@ In the |AC9IDE|, create a file with this content, and save the file with the nam
208215
function deleteMyBucket(callback) {
209216
console.log('\nDeleting the bucket named ' + bucket_name + '...\n');
210217
211-
s3.deleteBucket(params, function(err, data) {
218+
s3.deleteBucket(delete_bucket_params, function(err, data) {
212219
if (err) {
213220
console.log(err.code + ": " + err.message);
214221
}

doc_source/sample-php.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ In the |AC9IDE|, create a file with this content, and save the file with the nam
168168
date_default_timezone_set('YOUR_TIME_ZONE');
169169
170170
$bucketName = $argv[1];
171-
171+
$region = 'YOUR_REGION';
172172
$s3 = new Aws\S3\S3Client([
173-
'region' => 'YOUR_REGION',
173+
'region' => $region,
174174
'version' => '2006-03-01'
175175
]);
176176
@@ -195,7 +195,10 @@ In the |AC9IDE|, create a file with this content, and save the file with the nam
195195
196196
try {
197197
$promise = $s3->createBucketAsync([
198-
'Bucket' => $bucketName
198+
'Bucket' => $bucketName,
199+
'CreateBucketConfiguration' => [
200+
'LocationConstraint' => $region
201+
]
199202
]);
200203
201204
$promise->wait();

doc_source/sample-python.rst

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@ In this step, you install Python, which is required to run this sample.
5151
5252
sudo yum -y update
5353
54-
#. Install Python by running the :command:`install` command.
54+
#. Install Python by running one or more of these :command:`install` commands.
5555

5656
.. code-block:: sh
5757
5858
sudo yum -y install python27 # Installs Python 2.7.
59+
sudo yum -y install python36 # Installs Python 3.6.
60+
61+
.. note:: If you have Python 2 and 3 installed, and you want to use Python 3 but running the :command:`python --version` command outputs a version of Python 2, you can
62+
use Python 3 in one or more of the following ways:
63+
64+
* Instead of running
5965

6066
For more information, see `Download Python <https://www.python.org/downloads/>`_ on the Python website and `Installing Packages <https://packaging.python.org/installing/>`_
6167
in the :title:`Python Packaging User Guide`.
@@ -93,9 +99,11 @@ Step 3: Run the Code
9399
====================
94100

95101
#. In the |AC9IDE|, on the menu bar, choose :menuselection:`Run, Run Configurations, New Run Configuration`.
96-
#. On the :guilabel:`[New] - Idle` tab, choose :guilabel:`Runner: Auto`, and then choose :guilabel:`Python`.
102+
#. On the :guilabel:`[New] - Idle` tab, choose :guilabel:`Runner: Auto`, and then choose :guilabel:`Python 2` or :guilabel:`Python 3`, depending
103+
on which version of Python you want to use.
97104

98-
.. note:: If :guilabel:`Python` isn't available, you can create a custom runner for Python.
105+
.. note:: If :guilabel:`Python 2` or :guilabel:`Python 3` isn't available, you can create a custom runner for the version of Python that is installed in
106+
your |env|.
99107

100108
#. On the :guilabel:`[New] - Idle` tab, choose :guilabel:`Runner: Auto`, and then choose :guilabel:`New Runner`.
101109
#. On the :guilabel:`My Runner.run` tab, replace the tab's contents with this code.
@@ -112,6 +120,9 @@ Step 3: Run the Code
112120
#. On the :guilabel:`[New] - Idle` tab, choose :guilabel:`Runner: Auto`, and then choose :guilabel:`Python`.
113121
#. Choose the :guilabel:`hello.py` tab to make it active.
114122

123+
To use a specific version of Python that is installed in your |env|, change :code:`python` to the path to the Python executable in the preceding custom runner
124+
definition (for example, :code:`/usr/bin/python27`, :code:`/usr/bin/python36`, or similar).
125+
115126
#. For :guilabel:`Command`, type :kbd:`hello.py 5 9`. In the code, :code:`5` represents :code:`sys.argv[1]`,
116127
and :code:`9` represents :code:`sys.argv[2]`.
117128
#. Choose the :guilabel:`Run` button, and compare your output.
@@ -183,9 +194,10 @@ In the |AC9IDE|, create a file with this content, and save the file with the nam
183194
import sys
184195
import botocore
185196
197+
region = 'YOUR_REGION'
186198
s3 = boto3.client(
187199
's3',
188-
region_name = 'YOUR_REGION'
200+
region_name = region
189201
)
190202
191203
bucket_name = sys.argv[1]
@@ -206,7 +218,11 @@ In the |AC9IDE|, create a file with this content, and save the file with the nam
206218
# Create a new bucket.
207219
try:
208220
print("\nCreating a new bucket named '" + bucket_name + "'...\n")
209-
s3.create_bucket(Bucket = bucket_name)
221+
s3.create_bucket(Bucket = bucket_name,
222+
CreateBucketConfiguration = {
223+
'LocationConstraint': region
224+
}
225+
)
210226
except botocore.exceptions.ClientError as e:
211227
if e.response['Error']['Code'] == 'BucketAlreadyExists':
212228
print("Cannot create the bucket. A bucket with the name '" +
@@ -230,7 +246,8 @@ Step 6: Run the AWS SDK Code
230246
============================
231247

232248
#. On the menu bar, choose :menuselection:`Run, Run Configurations, New Run Configuration`.
233-
#. On the :guilabel:`[New] - Idle` tab, choose :guilabel:`Runner: Auto`, and then choose :guilabel:`Python`.
249+
#. On the :guilabel:`[New] - Idle` tab, choose :guilabel:`Runner: Auto`, and then choose :guilabel:`Python 2` or :guilabel:`Python 3`, depending
250+
on which version of Python you want to use and is installed in your |env|.
234251
#. For :guilabel:`Command`, type :samp:`s3.py {YOUR_BUCKET_NAME}`, where :samp:`{YOUR_BUCKET_NAME}` is the name of the bucket you want to create and then delete.
235252

236253
.. note:: |S3| bucket names must be unique across AWS |mdash| not just your AWS account.

doc_source/sample-ruby.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ In the |AC9IDE|, create a file with this content, and save the file with the nam
157157
require 'aws-sdk'
158158
159159
bucket_name = ARGV[0]
160-
161-
s3 = Aws::S3::Client.new(region: 'YOUR_REGION')
160+
region = 'YOUR_REGION'
161+
s3 = Aws::S3::Client.new(region: region)
162162
163163
# Lists all of your available buckets in this AWS Region.
164164
def list_my_buckets(s3)
@@ -176,7 +176,12 @@ In the |AC9IDE|, create a file with this content, and save the file with the nam
176176
# Create a new bucket.
177177
begin
178178
puts "\nCreating a new bucket named '#{bucket_name}'...\n\n"
179-
s3.create_bucket(bucket: bucket_name)
179+
s3.create_bucket({
180+
bucket: bucket_name,
181+
create_bucket_configuration: {
182+
location_constraint: region
183+
}
184+
})
180185
rescue Aws::S3::Errors::BucketAlreadyExists
181186
puts "Cannot create the bucket. " +
182187
"A bucket with the name '#{bucket_name}' already exists. Exiting."

0 commit comments

Comments
 (0)