AWS CloudFormation中的cfn-init找不到元数据

时间:2019-03-25 23:33:31

标签: amazon-web-services metadata amazon-cloudformation

我正在使用PHP应用程序和其他一些依赖项来设置cloudformation堆栈。

我正在尝试在启动配置中设置配置文件和元数据应用。

我的代码进行了验证-yaml语法没有问题,堆栈的其他部分也没问题,除了cfn-init找不到的元数据部分。

我可以确认cfn-init是否以必需的参数运行。但是由于某种原因找不到元数据。

当我在具有相同参数的实例中运行aws helper cfn-get-metadata时,我可以看到所有元数据都很好。

有帮助吗?这是我的元数据的cloudformation片段。我尚未包括触发cfn-init辅助函数的userdata部分。

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

0 个答案:

没有答案