Я использую тропосферу для генерации шаблона CloudFormation. Я пытаюсь создать группу автоматического масштабирования экземпляров EC2, работающих со стеком LAMP.
Мне нужно установить пакеты и создать файлы конфигурации на экземпляре EC2.
Прямо сейчас я указываю содержимое файла конфигурации встроенным методом Join.
LaunchConfig = t.add_resource(LaunchConfiguration(
"LaunchConfiguration",
Metadata=autoscaling.Metadata(
cloudformation.Init(
cloudformation.InitConfigSets(
install=['install']
),
"install": cloudformation.InitConfig(
"packages" : {
"apt-get" : {
"curl": [],
"zip": [],
"unzip": [],
"git": [],
"supervisor": [],
"sqlite3": [],
"nginx": [],
"php7.2-fpm": [],
"php7.2-cli": [],
"php7.2-pgsql": [],
"php7.2-sqlite3": [],
"php7.2-gd": [],
"php7.2-curl": [],
"php7.2-memcached": [],
"php7.2-imap": [],
"php7.2-mysql": [],
"php7.2-mbstring": [],
"php7.2-xml": [],
"php7.2-zip": [],
"php7.2-bcmath": [],
"php7.2-soap": [],
"php7.2-intl": [],
"php7.2-readline": [],
"php-msgpack": [],
"php-igbinary": []
}
),
{
"config": cloudformation.InitConfig(
files=cloudformation.InitFiles({
"/etc/nginx/sites-available/default": cloudformation.InitFile(
source=Join('', [
"server {",
" listen 80 default_server;",
" root /var/www/html/public;",
" index index.html index.htm index.php;",
" server_name _;",
" charset utf-8;",
" location = /favicon.ico { log_not_found off; access_log off; }",
" location = /robots.txt { log_not_found off; access_log off; }",
" location / {",
" try_files $uri $uri/ /index.php$is_args$args;",
" }",
" location ~ \.php$ {",
" include snippets/fastcgi-php.conf;",
" fastcgi_pass unix:/run/php/php7.2-fpm.sock;",
" }",
" error_page 404 /index.php;",
"}"
])
),
"/etc/supervisor/conf.d/supervisord.conf": cloudformation.InitFile(
source=Join('',[
"[supervisord]",
"nodaemon=true",
"[program:nginx]",
"command=nginx",
"stdout_logfile=/dev/stdout",
"stdout_logfile_maxbytes=0",
"stderr_logfile=/dev/stderr",
"stderr_logfile_maxbytes=0",
"[program:php-fpm]",
"command=php-fpm7.2",
"stdout_logfile=/dev/stdout",
"stdout_logfile_maxbytes=0",
"stderr_logfile=/dev/stderr",
"stderr_logfile_maxbytes=0",
"[program:horizon]",
"process_name=%(program_name)s",
"command=php /var/www/html/artisan horizon",
"autostart=true",
"autorestart=true",
"user=root",
"redirect_stderr=true",
"stdout_logfile=/var/www/html/storage/logs/horizon.log",
])
),
}),
services={
"sysvinit": cloudformation.InitServices({
"nginx": cloudformation.InitService(
enabled=True,
ensureRunning=True
)
})
}
)
}),
),
UserData=Base64(Join('', [
"#!/bin/bash\n",
"cfn-signal -e 0",
" --resource AutoscalingGroup",
" --stack ", Ref("AWS::StackName"),
" --region ", Ref("AWS::Region"), "\n"
])),
ImageId=Ref(AmiId),
KeyName=Ref(KeyName),
BlockDeviceMappings=[
ec2.BlockDeviceMapping(
DeviceName="/dev/sda1",
Ebs=ec2.EBSBlockDevice(
VolumeSize="8"
)
),
],
SecurityGroups=[Ref(SecurityGroup)],
InstanceType="t2.medium",
))
Есть ли способ сохранить эти конфигурационные файлы отдельно и просто загрузить их с помощью тропосферы?