View listPricingByRegion.js
const AWS = require('aws-sdk'); | |
const pricing = new AWS.Pricing({region: 'us-east-1'}); | |
const main = async () => { | |
const output = {}; | |
const prices = await pricing.getProducts({ | |
ServiceCode: "AmazonStates", |
View deploy.sh
# config | |
BUCKET_NAME=your-bucket-name | |
STACK_NAME=lambda-power-tuning-demo | |
# package | |
sam package --s3-bucket $BUCKET_NAME --template-file template.yml --output-template-file packaged.yml | |
# deploy | |
sam deploy --template-file packaged.yml --stack-name $STACK_NAME --capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM |
View italy.html.metadata.json
{ | |
"DocumentId": "Italy-document-ID", | |
"Attributes": { | |
"_category": "countries", | |
"_created_at": "2009-12-10T06:00:00", | |
"_last_updated_at": "2019-12-10T06:00:00", | |
"_version": "3.0", | |
"_view_count": 40000 | |
}, | |
"Title": "Italy Wikipedia", |
View template.yml
AWSTemplateFormatVersion : '2010-09-09' | |
Transform: AWS::Serverless-2016-10-31 | |
Parameters: | |
Subnets: | |
Type: List<AWS::EC2::Subnet::Id> | |
VpcId: | |
Type: AWS::EC2::VPC::Id | |
Resources: |
View index.py
import json | |
def lambda_handler(event, context): | |
name = get_name(event) # extract inputs | |
message = get_message(name) # business logic | |
return build_response(message) # format output for ALB | |
def get_name(event): | |
# fetch inputs from event (could be missing) | |
return event['queryStringParameters'].get('name') |
View index.py
def handler(event, context): | |
input = extract_input_from_event('ALB', event) | |
output = my_business_logic(input) | |
return format_output_for('ALB', output) | |
def extract_input_from_event(alb_or_apigw, event): | |
# extract data from input event | |
def format_output_for(alb_or_apigw, output): | |
# return a json object |
View response.json
{ | |
"statusCode": 200, | |
"statusDescription": "200 OK", | |
"isBase64Encoded": false, | |
"headers": { | |
"Content-Type": "application/json" | |
}, | |
"body": "{\"message\": \"Hello world!\"}" | |
} |
View event.json
{ | |
"requestContext": { | |
"elb": { | |
"targetGroupArn": "arn:aws:elasticloadbalancing:XXX:YYY:targetgroup/lambda-ZZZ" | |
} | |
}, | |
"httpMethod": "GET", | |
"path": "/my-new-feature", | |
"queryStringParameters": { | |
"id": "123" |
View template.yml
AWSTemplateFormatVersion : '2010-09-09' | |
Transform: AWS::Serverless-2016-10-31 | |
Resources: | |
myHookFunction: | |
Type: AWS::Serverless::Function | |
Properties: | |
Handler: index.handler | |
# ... | |
# all the other properties here |
View index.js
const https = require("https"); | |
/* FB configuration */ | |
const FB_ACCESS_TOKEN = "EAF...DZD"; | |
const FB_PSID = "facebookMessengerPsid"; | |
const FB_REQUEST = { | |
host: "graph.facebook.com", | |
path: "/v2.6/me/messages?access_token=" + FB_ACCESS_TOKEN, | |
method: "POST", | |
headers: { |
NewerOlder