Commit 4ed3f1dd authored by Vladimir Kiryakov's avatar Vladimir Kiryakov
Browse files

CloudFormation template

parent 03e072f2
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
KeyName:
ConstraintDescription: must be the name of an existing EC2 KeyPair.
Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
Type: AWS::EC2::KeyPair::KeyName
InstanceType:
AllowedValues:
- t2.micro
ConstraintDescription: must be a valid EC2 instance type.
Default: t2.micro
Description: WebServer EC2 instance type
Type: String
Mappings:
RegionMap:
us-east-1:
AMI: ami-43a15f3e
us-east-2:
AMI: ami-916f59f4
us-west-1:
AMI: ami-925144f2
eu-west-2:
AMI: ami-4e79ed36
Resources:
S3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: index.html
EC2Instance:
Type: AWS::EC2::Instance
Properties:
UserData: !Base64
Fn::Join:
- ''
- [IPAddress=, !Ref 'IPAddress']
InstanceType: !Ref 'InstanceType'
SecurityGroups: [!Ref 'InstanceSecurityGroup']
KeyName: !Ref 'KeyName'
ImageId: !FindInMap
- RegionMap
- !Ref 'AWS::Region'
- AMI
UserData:
Fn::Base64:
Fn::Sub: |
#!/bin/sh
add-apt-repository ppa:mosquitto-dev/mosquitto-ppa -y
apt-get update -y
apt-get install mosquitto -y
echo "
# /etc/mosquitto/mosquitto.conf
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_type all
connection_messages true
log_timestamp true
log_dest file /var/log/mosquitto/mosquitto.log
# Standard MQTT
listener 1883
protocol mqtt
# MQTT over websockets
listener 8000
protocol websockets
include_dir /etc/mosquitto/conf.d
" > /etc/mosquitto/mosquitto.conf
service mosquitto restart
InstanceSecurityGroup:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: SSH, MQTT, WS
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '1883'
ToPort: '1883'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '8000'
ToPort: '8000'
CidrIp: 0.0.0.0/0
IPAddress:
Type: AWS::EC2::EIP
IPAssoc:
Type: AWS::EC2::EIPAssociation
Properties:
InstanceId: !Ref 'EC2Instance'
EIP: !Ref 'IPAddress'
Outputs:
InstanceId:
Description: InstanceId of the newly created EC2 instance
Value: !Ref 'EC2Instance'
InstanceIPAddress:
Description: IP address of the newly created EC2 instance
Value: !Ref 'IPAddress'
WebsiteURL:
Value: !GetAtt [S3Bucket, WebsiteURL]
Description: URL for website hosted on S3
S3BucketSecureURL:
Value: !Join ['', ['https://', !GetAtt [S3Bucket, DomainName]]]
Description: Name of S3 bucket to hold website content
StackId:
Description: StackId
Value: !Ref "AWS::StackId"
StackName:
Description: StackName
Value: !Ref "AWS::StackName"
\ No newline at end of file
#!/bin/sh
add-apt-repository ppa:mosquitto-dev/mosquitto-ppa -y
apt-get update -y
apt-get install mosquitto -y
echo "
# /etc/mosquitto/mosquitto.conf
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_type all
connection_messages true
log_timestamp true
log_dest file /var/log/mosquitto/mosquitto.log
# Standard MQTT
listener 1883
protocol mqtt
# MQTT over websockets
listener 8000
protocol websockets
include_dir /etc/mosquitto/conf.d
" > /etc/mosquitto/mosquitto.conf
service mosquitto restart
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment