Skip to content

Instantly share code, notes, and snippets.

View adhorn's full-sized avatar

Adrian Hornsby adhorn

View GitHub Profile
@adhorn
adhorn / gist:a2f5a29a3ad3c20bc3dd21f61cca5861
Created April 24, 2018 11:51
Deploying using the serverless framework
# Deploy in the eu-west-1 region
serverless deploy --region eu-west-1
# Deploy in the eu-central-1 region
serverless deploy --region eu-central-1
(I am using the httpie https://httpie.org/ commandline tool)
http https://<YOUR API>.execute-api.eu-central-1.amazonaws.com/dev/get/foobar  ✔  14:49:30
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 112
Content-Type: application/json
Date: Tue, 24 Apr 2018 12:01:50 GMT
X-Amzn-Trace-Id: sampled=0;root=1-5adf1cae-c2edf25c6a7545c3e172478f
x-amz-apigw-id: F2FrSHB0liAFo4Q=
http POST https://<YOUR API>.execute-api.eu-west-1.amazonaws.com/dev/create "item_id"="barfoo"
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 22
Content-Type: application/json
Date: Tue, 24 Apr 2018 12:04:38 GMT
X-Amzn-Trace-Id: sampled=0;root=1-5adf1d55-50b949696dfd3547bb7f9f28
x-amz-apigw-id: F2GFbE1WDoEFuGA=
x-amzn-RequestId: a94e2c6f-47b7-11e8-8354-892b5fef891a
http https://globe.adhorn.me/get/foobar
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 112
Content-Type: application/json
Date: Tue, 24 Apr 2018 14:26:10 GMT
X-Amzn-Trace-Id: sampled=0;root=1-5adf3e82-30d3c630cf5b16ebbdceaf04
x-amz-apigw-id: F2a0YEk6FiAFWUw=
x-amzn-RequestId: 6f3a6121-47cb-11e8-8f1d-618431149814
for i in {1..10}
do http POST https://globe.adhorn.me/create "item_id"="boo$i"
done
@adhorn
adhorn / Command Line to create the VPC
Last active May 3, 2018 09:11
Serverless template for global backend in VPC with DynamoDB endpoint
# create VPC in region us-east-1
aws ec2 create-vpc --cidr-block 10.0.0.0/16 --region us-east-1
{
"Vpc": {
"CidrBlock": "10.0.0.0/16",
"DhcpOptionsId": "dopt-f14eca94",
"State": "pending",
"VpcId": "vpc-xxxxxx",
"InstanceTenancy": "default",
"Ipv6CidrBlockAssociationSet": [],
# create VPC in region us-east-1
aws ec2 create-vpc --cidr-block 10.0.0.0/16 --region us-east-1
{
"Vpc": {
"CidrBlock": "10.0.0.0/16",
"DhcpOptionsId": "dopt-f14eca94",
"State": "pending",
"VpcId": "vpc-xxxxxx",
# Create subnet associated with the VPC
aws ec2 create-subnet --vpc-id vpc-xxxxxx --cidr-block 10.0.1.0/24 --region us-east-1
{
"Subnet": {
"AvailabilityZone": "us-east-1b",
"AvailableIpAddressCount": 251,
"CidrBlock": "10.0.1.0/24",
"DefaultForAz": false,
"MapPublicIpOnLaunch": false,
"State": "pending",
# Get the routing info from the VPC.
aws ec2 describe-route-tables --filters "Name=vpc-id,Values=vpc-xxxxxxx" --region us-east-1
{
"RouteTables": [
{
"Associations": [
{
"Main": true,
"RouteTableAssociationId": "rtbassoc-4112743e",
"RouteTableId": "rtb-xxxxxx"
#create the initial table with stream enabled in us-east-1
aws dynamodb create-table \
--table-name MyGlobalTable \
--attribute-definitions \
AttributeName=item_id,AttributeType=S \
--key-schema \
AttributeName=item_id,KeyType=HASH \
--provisioned-throughput \
ReadCapacityUnits=5,WriteCapacityUnits=5 \
--stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \