简体   繁体   中英

cfn-init in aws cloudformation can't find metadata

I'm setting up cloudformation stack with a PHP application and few other dependencies.

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.

I can confirm that cfn-init runs with the required params. 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.

Any help? Here is my cloudformation snippet for metadata. I haven't included the userdata part that triggers cfn-init helper 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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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