Skip to content

Instantly share code, notes, and snippets.

View adhorn's full-sized avatar

Adrian Hornsby adhorn

View GitHub Profile
@adhorn
adhorn / gist:94a2413b32612997d089c105446b3c54
Last active July 22, 2018 23:29
Traffic Shifting Using an Alias (CLI)
(1) version 1 receiving 90% and version 2 receiving 10%
> aws lambda create-alias --name myalias --function-name myfunction --function-version 1 --routing-config AdditionalVersionWeights={"2"=0.1}
(2) you can update the percentage of incoming traffic to version 2, here to 15%.
> aws lambda update-alias --name myalias --function-name myfunction --routing-config AdditionalVersionWeights={"2"=0.15}
Eventually, after several cycle of incremental increase.
(n) you can route all traffic to version 2 by changing the function-version property to point to version 2 and set the routing-config parameter to an empty string, as shown following.
> aws lambda update-alias --name myalias --function-name myfunction --function-version 2 --routing-config ''
@adhorn
adhorn / gist:60c7abdbe0792d8732a8661b0837f278
Created July 22, 2018 23:21
Traffic shifting with Lambda Alias
Traffic Shifting Using an Alias (CLI)
To configure an alias to shift traffic between two function versions based on weights.
Here is an example that points an alias to two different Lambda function versions, starting with version 1 receiving 90% and version 2 receiving 10%
> aws lambda create-alias --name myalias --function-name myfunction --function-version 1 --routing-config AdditionalVersionWeights={"2"=0.1}
Then you can update the percentage of incoming traffic to version 2, here to 15%.
> aws lambda update-alias --name myalias --function-name myfunction --routing-config AdditionalVersionWeights={"2"=0.15}
1. Within the ASG1 that runs the service you want to update, find the number of instances required to serve the current traffic.
2. Start a new ASG2 with instances running the new version of the service. This should be a new golden AMI.
3. Launch the ASG2 with the same number of instances found in step 1 (+ typical 5-10%)
4. At this point, the new ASG2 is taking traffic along side ASG1.
5. De-attach the ASG1 from the ELB but don't stop the instances quite yet. This is your ticket to rollback.
6. If all looks good after few hours, you can dispose of ASG1.
START
Create a Base AMI and harden it if you have too.
IF DOCKER:
Create base Container with libraries and dependencies and store it in your container hub (you don't want to recreate the whole container every time)
Create an as-light-as possible Dockerfile (used a base container)
Copy code on build into Docker Container (run dockerfile)
Deploy Container to base AMI
@adhorn
adhorn / lambda.py
Created June 28, 2018 07:42
Lambda Function to check SQS Trigger
import json
def lambda_handler(event, context):
body = {
"message": "Hello SQS",
"event": event
}
print json.dumps(body)
@adhorn
adhorn / gist:8b0903c9807446ea90257b28ff191c19
Last active June 28, 2018 07:40
SQS Lambda Permission
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sqs:ListQueues",
"Resource": "*"
},
{
"Effect": "Allow",
@adhorn
adhorn / gist:cd15c271a05204712179cd27d6e07881
Created May 24, 2018 13:14
Filter ARN from DynamoDB table CLI query
aws dynamodb describe-table --table-name global2 --region us-east-1 --query "Table.LatestStreamArn"
"arn:aws:dynamodb:us-east-1:xxxxxxxxxxxx:table/global2/stream/2018-05-14T21:09:15.761"
from __future__ import unicode_literals
import sys
import logging
import boto3
import os
log = logging.getLogger()
log.setLevel(logging.DEBUG)
sys.path.insert(0, './vendored')
http POST https://global.adhorn.me/create "session_comment"="It is a love hate relationship" "item_id"="foobar11"  ✔  13:34:25
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 24
Content-Type: application/json
Date: Thu, 24 May 2018 10:46:14 GMT
X-Amzn-Trace-Id: Root=1-5b0697f6-8fb9c837297aa8e2e7e2ab7b
x-amz-apigw-id: HYyufGVvPHcF-OA=
x-amzn-RequestId: ae185ab8-5f3f-11e8-9bc3-61481c62f7b2
@adhorn
adhorn / gist:a2ad8cdba586e1c1e231bd007f0f064b
Created May 24, 2018 10:40
DynamoDB stream object - type INSERT
{
u'Records':[
{
u'eventID':u'09a77cc835e8baeeeec400efc3d69295',
u'eventVersion':u'1.1',
u'dynamodb':{
u'SequenceNumber':u'45152900000000035196046782',
u'Keys':{
u'item_id':{
u'S':u'foobar11'