Skip to content

Commit

Permalink
adding ec2 spot fleet multiple VPC example
Browse files Browse the repository at this point in the history
  • Loading branch information
schmutze committed Oct 21, 2018
1 parent 4c02187 commit 9a26f01
Show file tree
Hide file tree
Showing 5 changed files with 922 additions and 0 deletions.
100 changes: 100 additions & 0 deletions ec2-spot-analyze-costs/ec2-spot-analyze-costs.yaml
@@ -0,0 +1,100 @@
---
AWSTemplateFormatVersion: 2010-09-09
Description: Example of how to analyze EC2 Spot Instance costs
Metadata:
Author:
Description: Chad Schmutzer <schmutze@amazon.com>
License:
Description: 'Copyright 2017 Amazon.com, Inc. and its affiliates. All Rights Reserved.
Licensed under the Amazon Software License (the "License"). You may not use this file
except in compliance with the License. A copy of the License is located at
http://aws.amazon.com/asl/
or in the "license" file accompanying this file. This file is distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under the License.'
Outputs:
awsRegionId:
Description: The AWS Region ID your template was launched in
Value:
Ref: AWS::Region
Parameters:
bucketPrefix:
Default: 123456789012
Type: String
Resources:
lambdaExecutionRole:
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Version: '2012-10-17'
Path: /
Policies:
- PolicyDocument:
Statement:
- Action:
- logs:*
Effect: Allow
Resource: arn:aws:logs:*:*:*
Version: '2012-10-17'
PolicyName: root
Type: AWS::IAM::Role
lambdaFunction:
Properties:
Code:
ZipFile:
Fn::Sub: |
import boto3
def handler(event, context):
print(event)
return
Handler: index.handler
Role:
Fn::GetAtt:
- lambdaExecutionRole
- Arn
Runtime: python3.6
Type: AWS::Lambda::Function
lambdaInvokePermission:
Properties:
Action: lambda:InvokeFunction
FunctionName:
Fn::GetAtt:
- lambdaFunction
- Arn
Principal: s3.amazonaws.com
SourceAccount:
Ref: AWS::AccountId
SourceArn:
Fn::Join:
- ''
- - 'arn:aws:s3:::'
- Fn::Sub: ${bucketPrefix}-spot-instance-data-feed
Type: AWS::Lambda::Permission
s3Bucket:
DependsOn: lambdaInvokePermission
Properties:
BucketName:
Fn::Sub: ${bucketPrefix}-spot-instance-data-feed
NotificationConfiguration:
LambdaConfigurations:
- Event: s3:ObjectCreated:*
Filter:
S3Key:
Rules:
- Name: suffix
Value: gz
Function:
Fn::GetAtt:
- lambdaFunction
- Arn
Type: AWS::S3::Bucket
...
150 changes: 150 additions & 0 deletions ec2-spot-fleet-multiple-vpcs/ec2-spot-fleet-multiple-vpcs-vpca.yaml
@@ -0,0 +1,150 @@
---
AWSTemplateFormatVersion: 2010-09-09
Description: Example of EC2 Spot Fleet using multiple VPCs with hub and spoke configuration
(VPC A)
Mappings:
CidrMappings:
vpcA:
CIDR: 172.16.0.0/16
vpcAPublicSubnet1:
CIDR: 172.16.0.0/19
vpcAPublicSubnet2:
CIDR: 172.16.32.0/19
Metadata:
Author:
Description: Chad Schmutzer <schmutze@amazon.com>
License:
Description: 'Copyright 2017 Amazon.com, Inc. and its affiliates. All Rights Reserved.
Licensed under the Amazon Software License (the "License"). You may not use this file
except in compliance with the License. A copy of the License is located at
http://aws.amazon.com/asl/
or in the "license" file accompanying this file. This file is distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under the License.'
Outputs:
vpcA:
Value:
Ref: vpcA
vpcAPublicSubnet1:
Value:
Ref: vpcAPublicSubnet1
vpcAPublicSubnet2:
Value:
Ref: vpcAPublicSubnet2
Resources:
vpcA:
Properties:
CidrBlock:
Fn::FindInMap:
- CidrMappings
- vpcA
- CIDR
EnableDnsHostnames: true
EnableDnsSupport: true
Tags:
- Key: Name
Value: VPC A
Type: AWS::EC2::VPC
vpcAAttachGateway:
DependsOn:
- vpcA
- vpcAInternetGateway
Properties:
InternetGatewayId:
Ref: vpcAInternetGateway
VpcId:
Ref: vpcA
Type: AWS::EC2::VPCGatewayAttachment
vpcAInternetGateway:
DependsOn:
- vpcA
Type: AWS::EC2::InternetGateway
vpcAPublicRoute:
DependsOn:
- vpcAPublicRouteTable
- vpcAInternetGateway
- vpcAAttachGateway
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId:
Ref: vpcAInternetGateway
RouteTableId:
Ref: vpcAPublicRouteTable
Type: AWS::EC2::Route
vpcAPublicRouteTable:
DependsOn:
- vpcA
- vpcAAttachGateway
Properties:
Tags:
- Key: Name
Value: VPC A Public Route Table
VpcId:
Ref: vpcA
Type: AWS::EC2::RouteTable
vpcAPublicSubnet1:
DependsOn: vpcAAttachGateway
Properties:
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs:
Ref: AWS::Region
CidrBlock:
Fn::FindInMap:
- CidrMappings
- vpcAPublicSubnet1
- CIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: VPC A Public Subnet 1
VpcId:
Ref: vpcA
Type: AWS::EC2::Subnet
vpcAPublicSubnet1RouteTableAssociation:
DependsOn:
- vpcAPublicRouteTable
- vpcAPublicSubnet1
- vpcAAttachGateway
Properties:
RouteTableId:
Ref: vpcAPublicRouteTable
SubnetId:
Ref: vpcAPublicSubnet1
Type: AWS::EC2::SubnetRouteTableAssociation
vpcAPublicSubnet2:
DependsOn: vpcAAttachGateway
Properties:
AvailabilityZone:
Fn::Select:
- 1
- Fn::GetAZs:
Ref: AWS::Region
CidrBlock:
Fn::FindInMap:
- CidrMappings
- vpcAPublicSubnet2
- CIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: VPC A Public Subnet 2
VpcId:
Ref: vpcA
Type: AWS::EC2::Subnet
vpcAPublicSubnet2RouteTableAssociation:
DependsOn:
- vpcAPublicRouteTable
- vpcAPublicSubnet2
- vpcAAttachGateway
Properties:
RouteTableId:
Ref: vpcAPublicRouteTable
SubnetId:
Ref: vpcAPublicSubnet2
Type: AWS::EC2::SubnetRouteTableAssociation
...

0 comments on commit 9a26f01

Please sign in to comment.