WordPress example?

Hi,

ive gone through the book and while i like the idea (signed up for the vids as well!:)) , but still feel rather lost on how to use the cfc-modules (Maybe becasue i dont use clouformation?). Is there an example for say wordpress, where theres a db and a container talking.

apologies if this isnt the best place to ask… please let me where if theres somewhere better.

S

Hi!

You found the best place to ask your questions :wave:

All of the examples do exactly what you are looking for: connect an application with a MySQL database (provided by RDS Aurora Serverless). I believe that the PHP example comes closest to WordPress. Pages 35 ff. and 74 ff. are explaining how you configure your app to use the database and how it works. But I suggest to go trough chapter 1-3.

Let me know if this helps. Otherwise, a more concret question (what have you tried? where are you stuck? what is your goal? how does your Dockerfile look like?) would help to guide you.

Michael

Hi,

thanks for the reply…

So im basically piecing together the ec2-rds example and the fargate example. to load wordpress using the latest image from docker hub and rds postgres as the backend.

im now getting the error:

An error occurred (ValidationError) when calling the CreateChangeSet operation: [/Resources/Service/ClientSg] 'null' values are not allowed in templates

Any assistance in getting it working would be greatly appricated!

This is my current config.

EXAMPLE.YML

---

AWSTemplateFormatVersion: '2010-09-09'
Description: 'cfn-modules: Fargate ALB to single container example'
Resources:
  Alerting:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      Parameters:
        Email: 'stebennettsjb@gmail.com' # replace with your email address to receive alerts
        # HttpsEndpoint: 'https://api.marbot.io/v1/endpoint/xyz' # or uncommnet and receive alerts in Slack using marbot.io
      TemplateURL: './node_modules/@cfn-modules/alerting/module.yml'
  Vpc:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      Parameters:
        AlertingModule: !GetAtt 'Alerting.Outputs.StackName'
        S3Endpoint: 'false' # speed up the example
        DynamoDBEndpoint: 'false' # speed up the example
        FlowLog: 'false' # speed up the example
        NatGateways: 'false' # speed up the example
      TemplateURL: './node_modules/@cfn-modules/vpc/module.yml'
  Cluster:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      TemplateURL: './node_modules/@cfn-modules/ecs-cluster/module.yml'
  Alb:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      Parameters:
        VpcModule: !GetAtt 'Vpc.Outputs.StackName'
        AlertingModule: !GetAtt 'Alerting.Outputs.StackName'
      TemplateURL: './node_modules/@cfn-modules/alb/module.yml'
  AlbListener:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      Parameters:
        AlbModule: !GetAtt 'Alb.Outputs.StackName'
      TemplateURL: './node_modules/@cfn-modules/alb-listener/module.yml'
  Target:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      Parameters:
        AlbModule: !GetAtt 'Alb.Outputs.StackName'
        AlbListenerModule: !GetAtt 'AlbListener.Outputs.StackName'
        VpcModule: !GetAtt 'Vpc.Outputs.StackName'
        AlertingModule: !GetAtt 'Alerting.Outputs.StackName'
      TemplateURL: './node_modules/@cfn-modules/ecs-alb-target/module.yml'
  Service:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      Parameters:
        ClusterModule: !GetAtt 'Cluster.Outputs.StackName'
        VpcModule: !GetAtt 'Vpc.Outputs.StackName'
        TargetModule: !GetAtt 'Target.Outputs.StackName'
        AlertingModule: !GetAtt 'Alerting.Outputs.StackName'
        ClientSgModule1: !GetAtt 'ClientSg.Outputs.StackName'
        AppImage: 'wordpress:latest'
        AppEnvironment1Key: 'WORDPRESS_DB_HOST' # optional
        AppEnvironment1SecretModule: !GetAtt 'Database.Outputs.DnsName'
        AppEnvironment2Key: 'WORDPRESS_DB_USER' # optional
        AppEnvironment2Value: 'wp' # optional
        AppEnvironment3Key: 'WORDPRESS_DB_PASSWORD' # optional
        AppEnvironment3Value: 'insecure' # optional
        AppEnvironment4Key: 'WORDPRESS_DB_NAME' # optional
        AppEnvironment4Value: 'wordpress' # optional
        AppPort: '80'
      TemplateURL: './node_modules/@cfn-modules/fargate-service/module.yml'
    ClientSg:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      Parameters:
        VpcModule: !GetAtt 'Vpc.Outputs.StackName'
      TemplateURL: './node_modules/@cfn-modules/client-sg/module.yml'
  Database:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      Parameters:
        VpcModule: !GetAtt 'Vpc.Outputs.StackName'
        ClientSgModule: !GetAtt 'ClientSg.Outputs.StackName'
        AlertingModule: !GetAtt 'Alerting.Outputs.StackName'
        DBName: 'wordpress'
        DBMasterUsername: 'wp'
        DBMasterUserPassword: insecure
        DBBackupRetentionPeriod: '0' # speed up the example (do not set to 0 in production!)
        DBMultiAZ: 'false' # speed up the example (do not set to false in production!)
      TemplateURL: './node_modules/@cfn-modules/rds-postgres/module.yml'
Outputs:
  Url:
    Value: !Sub 'http://${Alb.Outputs.DnsName}'

Had the indention of ClientSg,

its now running! see what i get the other side :smiley:

Failed with error:

Waiting for changeset to be created..
Waiting for stack create/update to complete

Failed to create/update the stack. Run the following command
to fetch the list of events leading up to the failure
aws cloudformation describe-stack-events --stack-name wordpress

running: aws cloudformation describe-stack-events --stack-name wordpress outputs to big to post in here. :frowning:

It might be easier to find the error when having a look at the failed events via the AWS Management Console. Look for the first event with an error.

Hi thanks,

ran it again and watched in cloudwatch, it showed insuffient in rds but when i clicked on it it showed 0 results :confused:

i did a search through the output of the command and found “FAIL” here:

    {
        "StackId": "arn:aws:cloudformation:us-east-1:066566280911:stack/wordpress/89c99620-51bd-11ea-887a-12eeb59f3ad1",
        "EventId": "b9946e10-51be-11ea-a799-12301089d57f",
        "StackName": "wordpress",
        "LogicalResourceId": "wordpress",
        "PhysicalResourceId": "arn:aws:cloudformation:us-east-1:066566280911:stack/wordpress/89c99620-51bd-11ea-887a-12eeb59f3ad1",
        "ResourceType": "AWS::CloudFormation::Stack",
        "Timestamp": "2020-02-17T19:50:18.720Z",
        "ResourceStatus": "ROLLBACK_IN_PROGRESS",
        "ResourceStatusReason": "The following resource(s) failed to create: [Service]. . Rollback requested by user."
    },
    {
        "StackId": "arn:aws:cloudformation:us-east-1:066566280911:stack/wordpress/89c99620-51bd-11ea-887a-12eeb59f3ad1",
        "EventId": "Service-CREATE_FAILED-2020-02-17T19:50:17.820Z",
        "StackName": "wordpress",
        "LogicalResourceId": "Service",
        "PhysicalResourceId": "arn:aws:cloudformation:us-east-1:066566280911:stack/wordpress-Service-1LTY48HDL73AW/b24083b0-51be-11ea-9970-0a34514375d1",   
        "ResourceType": "AWS::CloudFormation::Stack",
        "Timestamp": "2020-02-17T19:50:17.820Z",
        "ResourceStatus": "CREATE_FAILED",
        "ResourceStatusReason": "Embedded stack arn:aws:cloudformation:us-east-1:066566280911:stack/wordpress-Service-1LTY48HDL73AW/b24083b0-51be-11ea-9970-0a34514375d1 was not successfully created: No export named wd1rzjzrew9l0d8.ceulecjjsvw3.us-east-1.rds.amazonaws.com-Arn found",
        "ResourceProperties": "{\"TemplateURL\":\"https://s3.amazonaws.com/cfn-modules-fargate-test2/22ac373a387c582c51670cd1e8f6819c.template\",\"Parameters\":{\"AppEnvironment4Key\":\"WORDPRESS_DB_NAME\",\"AlertingModule\":\"wordpress-Alerting-C2DLWHKL6HR3\",\"AppEnvironment2Key\":\"WORDPRESS_DB_USER\",\"AppEnvironment3Value\":\"insecure\",\"AppEnvironment3Key\":\"WORDPRESS_DB_PASSWORD\",\"AppImage\":\"wordpress:latest\",\"AppEnvironment4Value\":\"wordpress\",\"AppPort\":\"80\",\"ClusterModule\":\"wordpress-Cluster-F18DZOELDB0E\",\"AppEnvironment1SecretModule\":\"wd1rzjzrew9l0d8.ceulecjjsvw3.us-east-1.rds.amazonaws.com\",\"ClientSgModule1\":\"wordpress-ClientSg-18W8FNATSNNWO\",\"AppEnvironment2Value\":\"wp\",\"VpcModule\":\"wordpress-Vpc-IH02J68K0XHR\",\"TargetModule\":\"wordpress-Target-1VGWLBJC8KJKN\",\"AppEnvironment1Key\":\"WORDPRESS_DB_HOST\"}}"
    }

Created a gist, if that helps as well…

The error via CloudFormation is:

Logical ID: Service
Status: CREATE_FAILED
Status Reason:
Embedded stack arn:aws:cloudformation:us-east-1:066566280911:stack/wordpress-Service-1LTY48HDL73AW/b24083b0-51be-11ea-9970-0a34514375d1 was not successfully created: No export named wd1rzjzrew9l0d8.ceulecjjsvw3.us-east-1.rds.amazonaws.com-Arn found

I found a glitch:

AppEnvironment1SecretModule: !GetAtt 'Database.Outputs.DnsName'

change to

AppEnvironment1Value: !GetAtt 'Database.Outputs.DnsName'

!!! Thanks… thought it needed that when you passed it a parameter…

Its now installing to complete but i get a 502 gateway error when connecting to the alb sadly.

I was hoping i could look at the cloudformation designer to review the config but there are lots of files… is there a way to single complete view?

Have you had a chance to check out the logs from your container (see p 85 f.)?

Can you double check that the tasks in ECS are properly running and not restarted all the time?

Can you share your Dockerfile with us?

Hi!

stupid mistake… i was using postgres instead of mysql. changed that and it worked!

1 Like

I’m happy to hear that!

2 posts were split to a new topic: Confluence example