Skip to content

Instantly share code, notes, and snippets.

@anishshobithps
Created June 1, 2023 18:14
Show Gist options
  • Save anishshobithps/4678c79a749f835a59a7d5c2d49e3349 to your computer and use it in GitHub Desktop.
Save anishshobithps/4678c79a749f835a59a7d5c2d49e3349 to your computer and use it in GitHub Desktop.
AWSTemplateFormatVersion: 2010-09-09
Description: Create two EC2 instances, one for cron and one for mongo
Resources:
CronInstance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-0123456789abcdef0
SecurityGroups:
- !Ref CronSecurityGroup
UserData:
Fn::Base64: |
#!/bin/bash
echo "Installing cron"
sudo apt-get install cron
echo "Adding cron job"
echo "*/1 * * * * echo 'Hello World!' >> /var/log/cron.log" | sudo crontab -
MongoInstance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-0123456789abcdef0
SecurityGroups:
- !Ref MongoSecurityGroup
UserData:
Fn::Base64: |
#!/bin/bash
echo "Installing mongo"
sudo apt-get install mongodb
echo "Starting mongo"
sudo service mongodb start
CronSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow access to cron
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
MongoSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow access to mongo
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 27017
ToPort: 27017
CidrIp: 0.0.0.0/0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment