Julio Faerman - @faermanj
-
Why AWS?
open https://aws.amazon.com/what-is-cloud-computing/
-
Free?
open http://aws.amazon.com/free/
-
Serverless?
open https://aws.amazon.com/serverless/
-
Cloud9 IDE
open https://aws.amazon.com/cloud9/
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
nvm install node
nvm alias default node
npm install -g c9
curl https://pyenv.run | bash
pyenv install 3.7.2
pyenv global 3.7.2
open https://aws.amazon.com/lambda/
open https://aws.amazon.com/fargate/
open https://aws.amazon.com/serverless/sam/
Benefits of Using AWS SAM
- Single-deployment configuration
- Extension of AWS CloudFormation
- Built-in best practices
- Local debugging and testing
- Deep integration with development tools
sam init -r python3.7 -n pma-sam-demo
cd pma-sam-demo
c9 open hello_world/app.py
print(json.dumps(event, indent=4, sort_keys=True))
sam build
echo '{"hello":"world"}' | sam local invoke
sam local start-api -p 8080 --host 0.0.0.0
"preview running applications"
ARTIFACTS_BUCKET="pma-bucket-bcn"
aws s3 mb s3://$ARTIFACTS_BUCKET
sam package \
--output-template-file pma.out.yaml \
--s3-bucket $ARTIFACTS_BUCKET
aws s3 ls s3://$ARTIFACTS_BUCKET
c9 open pma.out.yaml
sam deploy \
--template-file pma.out.yaml \
--stack-name pma-sam-demo \
--capabilities CAPABILITY_IAM
open https://console.aws.amazon.com/cloudformation/home
aws cloudformation describe-stacks \
--stack-name pma-sam-demo \
--query 'Stacks[].Outputs'
open https://console.aws.amazon.com/apigateway/home
# https://console.aws.amazon.com/lambda/home
# https://console.aws.amazon.com/cloudwatch/home
sam logs -t -n HelloWorldFunction --stack-name pma-sam-demo
- Install and setup AWS Amplify CLI
npm install -g @aws-amplify/cli
# amplify configure
mkdir -p pma-amp-demo/src && cd pma-amp-demo
touch package.json index.html webpack.config.js src/app.js
´´´open https://docs.npmjs.com/files/package.json´´´ ´´´open https://webpack.js.org/´´´
- c9 open package.json
{
"name": "pma-demo",
"version": "1.0.0",
"description": "Positive Mental Attitude Demonstration",
"dependencies": {},
"devDependencies": {
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0",
"copy-webpack-plugin": "^4.5.2",
"webpack-dev-server": "^3.1.5"
},
"scripts": {
"start": "webpack && webpack-dev-server --mode development",
"build": "webpack"
}
}
npm install
- c9 open index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AWS Amplify</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html, body { font-family: "Amazon Ember", "Helvetica", "sans-serif"; margin: 0; }
a { color: #FF9900; }
h1 { font-weight: 300; }
.app { width: 100%; }
.app-header { color: white; text-align: center; background: linear-gradient(30deg, #f90 55%, #FFC300); width: 100%; margin: 0 0 1em 0; padding: 3em 0 3em 0; box-shadow: 1px 2px 4px rgba(0, 0, 0, .3); }
.app-logo { width: 126px; margin: 0 auto; }
.app-body { width: 400px; margin: 0 auto; text-align: center; }
.app-body button { background-color: #FF9900; font-size: 14px; color: white; text-transform: uppercase; padding: 1em; border: none; }
.app-body button:hover { opacity: 0.8; }
</style>
</head>
<body>
<div class="app">
<div class="app-header">
<div class="app-logo">
<img src="https://aws-amplify.github.io/images/Logos/Amplify-Logo-White.svg" alt="AWS Amplify" />
</div>
<h1>Welcome to AWS Amplify</h1>
</div>
</div>
<script src="main.bundle.js"></script>
</body>
</html>
- c9 open webpack.config.js
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
module.exports = {
mode: 'development',
entry: './src/app.js',
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/
}
]
},
devServer: {
contentBase: './dist',
overlay: true,
hot: true,
port: 8080,
host: '0.0.0.0'
},
plugins: [
new CopyWebpackPlugin(['index.html']),
new webpack.HotModuleReplacementPlugin()
]
};
npm start
npm install --save aws-amplify
amplify init
amplify add hosting
amplify publish
amplify add analytics
c9 open ./src/aws-exports.js
- c9 open index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AWS Amplify</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html, body { font-family: "Amazon Ember", "Helvetica", "sans-serif"; margin: 0; }
a { color: #FF9900; }
h1 { font-weight: 300; }
.app { width: 100%; }
.app-header { color: white; text-align: center; background: linear-gradient(30deg, #f90 55%, #FFC300); width: 100%; margin: 0 0 1em 0; padding: 3em 0 3em 0; box-shadow: 1px 2px 4px rgba(0, 0, 0, .3); }
.app-logo { width: 126px; margin: 0 auto; }
.app-body { width: 400px; margin: 0 auto; text-align: center; }
.app-body button { background-color: #FF9900; font-size: 14px; color: white; text-transform: uppercase; padding: 1em; border: none; }
.app-body button:hover { opacity: 0.8; }
</style>
</head>
<body>
<div class="app">
<div class="app-header">
<div class="app-logo">
<img src="https://aws-amplify.github.io/images/Logos/Amplify-Logo-White.svg" alt="AWS Amplify" />
</div>
<h1>Welcome to AWS Amplify</h1>
</div>
<!-- Register an Pinpoint Event -->
<div class="app-body">
<button id="AnalyticsEventButton">Generate Analytics Event</button>
<div id="AnalyticsResult"></div>
</div>
</div>
<script src="main.bundle.js"></script>
</body>
</html>
c9 open ./src/app.js
import Auth from '@aws-amplify/auth';
import Analytics from '@aws-amplify/analytics';
import awsconfig from './aws-exports';
// retrieve temporary AWS credentials and sign requests
Auth.configure(awsconfig);
// send analytics events to Amazon Pinpoint
Analytics.configure(awsconfig);
const AnalyticsResult = document.getElementById('AnalyticsResult');
const AnalyticsEventButton = document.getElementById('AnalyticsEventButton');
let EventsSent = 0;
AnalyticsEventButton.addEventListener('click', (evt) => {
Analytics.record('AWS Amplify Tutorial Event')
.then( (evt) => {
const url = 'https://'+awsconfig.aws_project_region+'.console.aws.amazon.com/pinpoint/home/?region='+awsconfig.aws_project_region+'#/apps/'+awsconfig.aws_mobile_analytics_app_id+'/analytics/events';
AnalyticsResult.innerHTML = '<p>Event Submitted.</p>';
AnalyticsResult.innerHTML += '<p>Events sent: '+(++EventsSent)+'</p>';
AnalyticsResult.innerHTML += '<a href="'+url+'" target="_blank">View Events on the Amazon Pinpoint Console</a>';
});
});
amplify publish
amplify status
open https://console.aws.amazon.com/pinpoint/home
open https://console.aws.amazon.com/codestar/home
-
re:Invent 2018 Serverless Breakout Sessions https://www.youtube.com/playlist?list=PLhr1KZpdzukcZIPswLEcVzw8HKF_yM0r3
-
AWS Serverless Hero https://aws.amazon.com/developer/community/heroes/#Serverless_Heroes
https://aws.amazon.com/developer/community/evangelists/julio-faerman/