You can access EC2 Instance or Cloud9 to perform the setup steps.
This lab requires a terminal shell with Python3 and the AWS Command Line Interface (CLI) installed and configured with admin credentials.
Choose Services at the top of the page, and then choose Cloud9 under Developer Tools.
There will be an environment ready to use under My environments.
Click on Open under Cloud9 IDE, and your IDE should open with a welcome note.
You should now see your AWS Cloud9 environment. You need to be familiar with the three areas of the AWS Cloud9 console shown in the following screenshot:
File explorer: On the left side of the IDE, the file explorer shows a list of the files in your directory.
File editor: On the upper right area of the IDE, the file editor is where you view and edit files that you’ve selected in the file explorer.
Terminal: On the lower right area of the IDE, this is where you run commands to execute code samples.
aws sts get-caller-identity
to verify the AWS CLI is functioningpython3 --version
to verify that python3 is installedsudo python3 -m pip install chalice
to install AWS Chalice .You may see a couple of WARNING lines near the bottom of the command output, these are safely ignored.
curl -O https://amazon-dynamodb-labs.com/assets/global-serverless.zip
unzip global-serverless.zip && cd global-serverless
aws dynamodb create-table \
--region us-west-2 \
--table-name global-serverless \
--attribute-definitions \
AttributeName=PK,AttributeType=S \
AttributeName=SK,AttributeType=S \
--key-schema \
AttributeName=PK,KeyType=HASH \
AttributeName=SK,KeyType=RANGE \
--billing-mode PAY_PER_REQUEST \
--query '{"New Table ":TableDescription.TableArn,
"Status ":TableDescription.TableStatus }'
Check to see when the table status changes from CREATING
to ACTIVE
by running this command:
aws dynamodb describe-table \
--table-name global-serverless \
--region us-west-2 \
--query '{TableStatus: Table.TableStatus}'
3.Our table is in us-west-2 (Oregon). Let’s make it a Global Table by requesting a replica in eu-west-1 (Europe/Dublin).
Run this command to create a new replica in the eu-west-1 (Europe/Dublin) region:
aws dynamodb update-table --table-name global-serverless --region us-west-2 --cli-input-json \
'{"ReplicaUpdates": [
{
"Create": {"RegionName": "eu-west-1" }
}
]}'
Check to see when the table replica status changes to ACTIVE
by running this command:
aws dynamodb describe-table \
--table-name global-serverless \
--region us-west-2 \
--query '{TableStatus: Table.TableStatus,
Replicas: Table.Replicas}'
Run this command to load video library items into the table with batch-write-item:
aws dynamodb batch-write-item \
--region us-west-2 \
--request-items file://sample-data.json
These items are how the UI will display which videos are available to stream.
aws dynamodb get-item \
--table-name global-serverless \
--region us-west-2 \
--key '{"PK": {"S": "library"}, "SK": {"S": "01"}}'
export AWS_DEFAULT_REGION=us-west-2
to instruct Chalice to deploy into us-west-2 for our first regionchalice deploy
and wait for the infrastructure to be created. Chalice is a Python based serverless framework./api/scan
You should see a JSON response representing the results of a table scan.[
A single-page static web app is provided for you.
Steps:
You now have a test harness where you can perform reads and writes to a DynamoDB record via the custom API.
export AWS_DEFAULT_REGION=eu-west-1
to instruct Chalice to deploy into eu-west-1 for our second region.chalice deploy
and wait for the infrastructure to be created in eu-west-1.Note: In this workshop you have permissions for Global Tables in us-west-2 and eu-west-1. In your own account you could add any number of replicas in any regions.
Note 2: If you make any changes to the code in app.py
, you can push the updates to your Lambda function
by running chalice deploy
again.