简体   繁体   English

aws cloudformation 中的 cfn-init 找不到元数据

[英]cfn-init in aws cloudformation can't find metadata

I'm setting up cloudformation stack with a PHP application and few other dependencies.我正在使用 PHP 应用程序和其他一些依赖项设置 cloudformation 堆栈。

I am trying to setup configuration files and appliclation with metadata inside launch-configuration.我正在尝试使用启动配置中的元数据设置配置文件和应用程序。

My code validates - no issues with yaml syntax and other part of stack is fine except for metadata part which cfn-init can't find.我的代码验证 - yaml 语法和堆栈的其他部分没有问题,除了 cfn-init 找不到的元数据部分。

I can confirm that cfn-init runs with the required params.我可以确认 cfn-init 使用所需的参数运行。 But for some reason can't find metadata.但由于某种原因找不到元数据。

When I run aws helper cfn-get-metadata inside instance with the same params, I can see metadata all fine.当我在具有相同参数的实例内运行 aws helper cfn-get-metadata 时,我可以看到元数据一切正常。

Any help?有什么帮助吗? Here is my cloudformation snippet for metadata.这是我用于元数据的 cloudformation 片段。 I haven't included the userdata part that triggers cfn-init helper function.我没有包含触发 cfn-init 助手 function 的用户数据部分。

LaunchConfig:
    Type: AWS::AutoScaling::LaunchConfiguration
    Metadata:
      AWS::CloudFormation::init:
        configSets:
          app_install:
            - configure_cfn
            - configure_nginx
            - install_packages
          configure_cfn:
            files:
              "/etc/cfn/cfn-hup.conf":
                content:
                  Fn::Join:
                    - ""
                    - - "[main]\n"
                      - stack=
                      - Ref: AWS::StackId
                      - "\n"
                      - region=
                      - Ref: AWS::Region
                      - "\n"
                mode: "000400"
                owner: root
                group: root
              "/etc/cfn/hooks.d/cfn-auto-reloader.conf":
                content:
                  Fn::Join:
                    - ""
                    - - "[cfn-auto-reloader-hook]\n"
                      - "triggers=post.update"
                      - "path=Resources.LaunchConfig.Metadata.AWS::CloudFormation::Init"
                      - "action=/opt/aws/bin/cfn-init -v "
                      - "         --stack "
                      - Ref: AWS::StackName
                      - "         --resource LaunchConfig "
                      - "         --configsets app_install "
                      - "         --region "
                      - Ref: AWS::Region
                      - "\n"
                mode: "000400"
                owner: root
                group: root

          configure_nginx:
            files:
              "/etc/cfn/cfn-hup.conf":
                content:
                  Fn::Join:
                    - ""
                    - - "[main]\n"
                      - stack=
                      - Ref: AWS::StackId
                      - "\n"
                      - region=
                      - Ref: AWS::Region
                      - "\n"
                mode: "000400"
                owner: root
                group: root

          install_packages:
            packages:
              yum:
                nginx: []
                php71: []
                php-common: []
                php71-fpm: []
                php71-devel: []
                php71-mcrypt: []
                php71-xml: []
                php71-common: []
                php71-pdo: []
                php71-mbstring: []
                php7-pear: []
                gcc: []
                awslogs: []
            files:
              /etc/nginx/conf.d/app.conf:
                content: |
                  server {
                    listen 80;
                    server_name _;
                    # note that these lines are originally from the "location /" block
                    root /var/www/app;
                    autoindex on;
                    index index.php index.html index.htm;
                    location = /favicon.ico {
                            log_not_found off;
                            access_log off;
                    }
                    location = /robots.txt {
                            allow all;
                            log_not_found off;
                            access_log off;
                    }
                    location / {
                                try_files $uri $uri/ /index.php?$uri&$args;
                    }
                    location ~* \.(js|css|png|jpg|jpeg|gif|ico)\$ {
                            expires max;
                            log_not_found off;
                    }
                    error_page 404 /404.html;
                    error_page 500 502 503 504 /50x.html;
                    location = /50x.html {
                        root /usr/share/nginx/html;
                    }

                    #location ~ \.php$ {
                    location ~ [^/]\.php(/|$) {

                      fastcgi_split_path_info  ^(.+\.php)(/.+)$;
                      fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                      fastcgi_index index.php;
                      fastcgi_buffers 16 16k;
                      fastcgi_buffer_size 32k;
                      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                      include fastcgi_params;
                    }
                    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|pdf)$ {
                    expires 30d;
                    }
                    location ~ /\.ht {
                                deny all;
                    }
                  }
            services:
              sysvinit:
                cfn-hup:
                  enabled: true
                  ensureRunning: true
                  files:
                    - "/etc/cfn/cfn-hup.conf"
                    - "/etc/cfn/hooks.d/cfn-auto-reloader.conf"
                nginx:
                  enabled: true
                  ensureRunning: true

Something as easy as this?这么简单的事情? Init vs init?初始化与初始化?
AWS::CloudFormation::init: vs AWS::CloudFormation:: I nit: AWS::CloudFormation::init: vs AWS::CloudFormation:: I nit:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM