Skip to content

Commit 14a4184

Browse files
committed
Add AWS CloudFormation template #65
1 parent bb0fb99 commit 14a4184

File tree

2 files changed

+245
-0
lines changed

2 files changed

+245
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ hostname = "https://my.test.host:4443"
7272

7373
Server will be accessible from `http://localhost:8080`, but episode links will point to `https://my.test.host:4443/ID1/...`
7474

75+
## One click deployment
76+
77+
[![Deploy to AWS](https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png)](https://console.aws.amazon.com/cloudformation/home?region=us-west-1#/stacks/new?stackName=Podsync&templateURL=https://podsync-cf.s3.amazonaws.com/cloud_formation.yml)
78+
7579
## How to run
7680

7781
Run as binary:

cloud_formation.yml

+241
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
3+
Parameters:
4+
InstanceType:
5+
Type: String
6+
Default: t3.micro
7+
Description: EC2 machine instance size (see https://aws.amazon.com/ec2/instance-types/)
8+
9+
KeyName:
10+
Type: AWS::EC2::KeyPair::KeyName
11+
Description: SSH key to use for logging in (see https://docs.aws.amazon.com/ground-station/latest/ug/create-ec2-ssh-key-pair.html)
12+
13+
AmiId:
14+
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
15+
Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
16+
Description: Amazon Linux 2 image ID (leave this as is)
17+
18+
VolumeSize:
19+
Type: Number
20+
Default: 64
21+
MinValue: 16
22+
Description: Disk size in Gb to allocate for storing downloaded episodes
23+
24+
PodsyncVersion:
25+
Type: String
26+
Default: latest
27+
Description: Podsync version to use (see https://github.com/mxpv/podsync/releases)
28+
29+
PodsyncPort:
30+
Type: Number
31+
Default: 8080
32+
MaxValue: 65535
33+
Description: Server port to use
34+
35+
YouTubeApiKey:
36+
Type: String
37+
Default: ''
38+
Description: |
39+
Key to use for YouTube API access (see https://github.com/mxpv/podsync/blob/master/docs/how_to_get_youtube_api_key.md)
40+
41+
VimeoAccessToken:
42+
Type: String
43+
Default: ''
44+
Description: |
45+
Key to use for Vimeo API access (see https://github.com/mxpv/podsync/blob/master/docs/how_to_get_vimeo_token.md)
46+
47+
FeedId:
48+
Type: String
49+
Default: 'ID1'
50+
AllowedPattern: '.+' # Required
51+
Description: |
52+
ID to use for the feed (you'll access it as http://localhost/ID1.xml)
53+
54+
FeedUrl:
55+
Type: String
56+
AllowedPattern: '.+'
57+
Description: |
58+
YouTube or Vimeo URL to host with Podsync (for example: https://www.youtube.com/user/XYZ)
59+
60+
PageSize:
61+
Type: Number
62+
Default: 50
63+
MinValue: 10
64+
Description: |
65+
The number of episodes to query each time
66+
67+
Format:
68+
Type: String
69+
AllowedValues:
70+
- 'audio'
71+
- 'video'
72+
Default: 'video'
73+
Description: Feed format (audio or video)
74+
75+
Quality:
76+
Type: String
77+
AllowedValues:
78+
- 'high'
79+
- 'low'
80+
Default: 'high'
81+
Description: Feed quality (high or low)
82+
83+
Metadata:
84+
AWS::CloudFormation::Interface:
85+
ParameterGroups:
86+
- Label:
87+
default: 'VM configuration'
88+
Parameters:
89+
- InstanceType
90+
- KeyName
91+
- AmiId
92+
- VolumeSize
93+
- Label:
94+
default: 'Podsync configuration'
95+
Parameters:
96+
- PodsyncVersion
97+
- PodsyncPort
98+
- YouTubeApiKey
99+
- VimeoAccessToken
100+
- Label:
101+
default: 'Feed configuration'
102+
Parameters:
103+
- FeedId
104+
- FeedUrl
105+
- PageSize
106+
- Format
107+
- Quality
108+
109+
ParameterLabels:
110+
InstanceType:
111+
default: 'Instance type'
112+
KeyName:
113+
default: 'SSH key name'
114+
AmiId:
115+
default: 'AMI ID'
116+
VolumeSize:
117+
default: 'Volume size'
118+
PodsyncVersion:
119+
default: 'Version'
120+
PodsyncPort:
121+
default: 'Server port'
122+
YouTubeApiKey:
123+
default: 'YouTube API Key'
124+
VimeoAccessToken:
125+
default: 'Vimeo Token'
126+
FeedId:
127+
default: 'Feed ID'
128+
FeedUrl:
129+
default: 'Feed URL'
130+
PageSize:
131+
default: 'Page size'
132+
133+
Resources:
134+
Ec2Instance:
135+
Type: AWS::EC2::Instance
136+
CreationPolicy:
137+
ResourceSignal:
138+
Count: 1
139+
Properties:
140+
InstanceType: !Ref InstanceType
141+
KeyName: !Ref KeyName
142+
ImageId: !Ref AmiId
143+
SecurityGroups:
144+
- !Ref AccessSecurityGroup
145+
EbsOptimized: true
146+
BlockDeviceMappings:
147+
- DeviceName: /dev/xvda
148+
Ebs:
149+
VolumeSize: !Ref VolumeSize
150+
IamInstanceProfile: !Ref SsmInstanceProfile
151+
Tags:
152+
- Key: 'Name'
153+
Value: !Sub "${AWS::StackName}"
154+
UserData:
155+
Fn::Base64: !Sub |
156+
#!/usr/bin/env bash
157+
set -ex
158+
trap '/opt/aws/bin/cfn-signal --exit-code 1 --resource Ec2Instance --region ${AWS::Region} --stack ${AWS::StackName}' ERR
159+
160+
# Install Docker
161+
yum update -y
162+
amazon-linux-extras install docker
163+
systemctl start docker
164+
usermod -a -G docker ec2-user
165+
166+
# Create configuration file
167+
mkdir -p /home/ec2-user/podsync/data
168+
tee /home/ec2-user/podsync/config.toml <<EOF
169+
[server]
170+
port = ${PodsyncPort}
171+
data_dir = "/home/ec2-user/podsync/data"
172+
173+
[tokens]
174+
youtube = "${YouTubeApiKey}"
175+
vimeo = "${VimeoAccessToken}"
176+
177+
[feeds]
178+
[feeds.${FeedId}]
179+
url = "${FeedUrl}"
180+
page_size = ${PageSize}
181+
quality = "${Quality}"
182+
format = "${Format}"
183+
EOF
184+
185+
# Pull image and run CLI
186+
docker pull mxpv/podsync:${PodsyncVersion}
187+
docker run -d \
188+
-p ${PodsyncPort}:${PodsyncPort} \
189+
-v /home/ec2-user/podsync/data:/app/data \
190+
-v /home/ec2-user/podsync/config.toml:/app/config.toml \
191+
--restart always \
192+
mxpv/podsync:${PodsyncVersion}
193+
194+
# Signal ok
195+
/opt/aws/bin/cfn-signal --exit-code 0 --resource Ec2Instance --region ${AWS::Region} --stack ${AWS::StackName}
196+
197+
# Setup instance profile with SSM policy. This let's connect to the EC2 machine via SSM console
198+
SsmIamRole:
199+
Type: AWS::IAM::Role
200+
Properties:
201+
RoleName: !Sub "${AWS::StackName}"
202+
AssumeRolePolicyDocument:
203+
Version: 2012-10-17
204+
Statement:
205+
- Effect: Allow
206+
Principal:
207+
Service:
208+
- ec2.amazonaws.com
209+
Action:
210+
- 'sts:AssumeRole'
211+
ManagedPolicyArns:
212+
- 'arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore'
213+
214+
SsmInstanceProfile:
215+
Type: AWS::IAM::InstanceProfile
216+
Properties:
217+
InstanceProfileName: !Sub "${AWS::StackName}"
218+
Roles:
219+
- !Ref SsmIamRole
220+
221+
# Limit access to SSH and CLI server
222+
AccessSecurityGroup:
223+
Type: AWS::EC2::SecurityGroup
224+
Properties:
225+
GroupDescription: !Sub "Podsync CLI security group for ${AWS::StackName}"
226+
SecurityGroupIngress:
227+
- IpProtocol: tcp
228+
FromPort: !Ref PodsyncPort
229+
ToPort: !Ref PodsyncPort
230+
CidrIp: 0.0.0.0/0
231+
Description: Access to Podsync server
232+
- IpProtocol: tcp
233+
FromPort: 22
234+
ToPort: 22
235+
CidrIp: 0.0.0.0/0
236+
Description: SSH access to EC2 machine
237+
238+
Outputs:
239+
PodsyncUrl:
240+
Description: 'Feed URL'
241+
Value: !Sub "http://${Ec2Instance.PublicDnsName}:${PodsyncPort}/${FeedId}/"

0 commit comments

Comments
 (0)