Attini deployment plan

Attini::Deploy::DeploymentPlan

Attini’s DeploymentPlan is a an abstraction on the AWS::Serverless::StateMachine resource. It extends the StateMachine with features that is required for the AWS::Serverless::StateMachine to function as a Deployment orchestrator ex by finding the deployment source files, automatic triggers and supporting additional Attini State Types.

Note

The DeploymentPlan can ONLY be created in the Attini init deploy stack

Type: Attini::Deploy::DeploymentPlan
Properties:
  DefinitionSubstitutions: Map
  RoleArn: String
  Tags: List
  DeploymentPlan: DeploymentPlan
DefinitionSubstitutions

Type: Map<Sting, Sting|Map>

AWS SAM compatibility: This property is passed directly to the DefinitionSubstitutions property of an AWS::Serverless::StateMachine resource.

This is useful if you want yo use AWS CloudFormation Condition functions when you build your deployment plan. This can also be used for Intrinsic functions but most of them (Ex Fn::Sub and Fn::Ref) can also be written straight in the DeploymentPlan.

Required: No

RoleArn

Type: String

AWS SAM compatibility: This property is passed directly to the Role property of an AWS::Serverless::StateMachine resource.

Default: arn:aws:iam::{Account}:role/attini/attini-deployment-plan-default-states-service-role-{Region}

Required: Conditional

If the parameter CreateDeploymentPlanDefaultRole on the attini-setup CloudFormation stack is false, then this is required.

Tags

Type: Map<Sting, Sting>

AWS SAM compatibility: This property is passed directly to the Tags property of an AWS::Serverless::StateMachine resource.

Required: No

DeploymentPlan

Type: DeploymentPlan

DeploymentPlan

Required: Yes


DeploymentPlan

A definition using Amazon state language that describes your deployment.

In extension to the Amazon state language the DeploymentPlan can also use the Attini types.

This definition converts to a Definition.

StartAt: String
States: Map
StartAt

Type: String

The step that the Deployment Plan should start with. This is passed directly the StartAt property in the Amazon States Language

Required: Yes

States

Type: Map<Sting, Map>

This is passed to the States property in the Amazon States Language after the Attini specific resources (ex AttiniCfn) have been converted into a valid Amazon States Language definition.

Make sure that the actions that you specify here are allowed by the DeploymentPlan Role.

This map have limited support for CloudFormation functions.

  • Simple functions like “Ref”, “Fn::GetAtt” and “Fn::Sub” works like normal CloudFormation.

  • Complex functions like “Fn::Join” will need to use the DefinitionSubstitutions property.

  • Conditions are not supported. you can often work around this limitation using logic in your definition, example by using the Choice state.

Required: Yes


Transformed resources

A Attini::Deploy::DeploymentPlan resource transforms into multiple CloudFormation resources that togethers creates your deployment plan.

The is example of how the transforms will look.

Original template:

AWSTemplateFormatVersion: "2010-09-09"
Transform:
  - AttiniDeploymentPlan
  - AWS::Serverless-2016-10-31

Resources:
  PublicWebsite:
    Type: Attini::Deploy::DeploymentPlan
    Properties:
      DeploymentPlan:
        ...

Outputs:
  DeploymentSfnPlanArn:
    Description: The arn of the StepFunction generated by PublicWebsite
    Value: !Ref AttiniDeploymentPlanSfnPublicWebsite

Transformed template:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "AttiniDeploymentPlanSfnTriggerPublicWebsite": {
      "Type": "Custom::AttiniDeploymentPlanTrigger",
      "Properties": {
        "...": "..."
      }
    },
    "AttiniDeploymentPlanSfnPublicWebsite": {
      "Type": "AWS::StepFunctions::StateMachine",
      "Properties": {
        "...": "..."
      }
    },
    "AttiniPostExecutionActionsPublicWebsite": {
      "Type": "AWS::Events::Rule",
      "Properties": {
        "...": "..."
      }
    }
  },
  "Outputs": {
    "DeploymentSfnPlanArn": {
      "Description": "The arn of the StepFunction generated by PublicWebsite deployment plan",
      "Value": {
        "Ref": "AttiniDeploymentPlanSfnPublicWebsite"
      }
    }
  }
}

Examples

A simple static website

  1. StaticWebsite is a step that deploys a s3 bucket and a Cloudfront distribution via CloudFormation.

  2. Deploys a lambda using CloudFormation.

  3. Trigger the lambda that copy’s the files from the Attini distribution to the website bucket and invalidates the Cloudfront distribution.

StaticWebsiteDeployPlan:
  Type: Attini::Deploy::DeploymentPlan
  Properties:
    DeploymentPlan:
      StartAt: StaticWebsite
      States:
        StaticWebsite:
          Type: AttiniCfn
          Properties:
            Template: /cfn-templates/static-website.yaml
            StackName: !Sub ${AttiniEnvironmentName}-public-documentation-website
            Parameters:
              AttiniEnvironmentName: !Ref AttiniEnvironmentName
          Next: DeployWebsiteLambda

        DeployWebsiteLambda:
          Type: AttiniCfn
            Properties:
            Template: /deploy-website/template.yaml
            StackName: !Sub ${AttiniEnvironmentName}-deploy-documentation-function
            ConfigFile: /config/default.json
          Parameters:
            StaticWebsiteBucketName.$: !Sub $.CfnOutput.${AttiniEnvironmentName}-public-documentation-website.WebassetsBucket
            CloudFrontDistributionId.$: !Sub $.CfnOutput.${AttiniEnvironmentName}-public-documentation-website.CloudFrontDistributionId
          Next: DeployWebsiteContent

        DeployWebsiteContent:
          Type: Task
          Resource: arn:aws:states:::lambda:invoke
          Parameters:
            FunctionName.$: !Sub $.CfnOutput.${AttiniEnvironmentName}-deploy-documentation-function.DeployWebsiteFunctionName
            Payload.$: $
          End: true