source

You can use the sources key to download an archive file and unpack it in a target directory on the EC2 instance. This key is fully supported for both Linux and Windows systems. The source method maps to the AWS::CloudFormation::Init sources section.

Example

source("/opt/cfn-demo" => "https://github.com/user1/cfn-demo/tarball/master")

Generates:

AWS::CloudFormation::Init:
  configSets:
    default:
    - main
  main:
    sources:
      "/opt/cfn-demo": https://github.com/user1/cfn-demo/tarball/master

Private S3 Source

Private S3 sources require a AWS::CloudFormation::Authentication resource. Lono can dynamically add the resource with the authentication method. Example:

authentication "IamRole" # adjust to match IamRole in template
source("/opt/mygem" => s3_file("files/mygem")) # uses files/mygem folder

The s3_file("files/mygem") corresponds to the files/mygem folder within the configset. For example:

app/configsets/myconfigset/files/mygem

The code uses this info to generate:

---
AWS::CloudFormation::Init:
  configSets:
    default:
    - main
  main:
    sources:
      "/opt/mygem": https://lono-bucket-12di8xz5sy72z.s3-us-west-2.amazonaws.com/dev/output/BLUEPRINT/configsets/mygem/files/mygem-file-a328be46.zip
AWS::CloudFormation::Authentication:
  rolebased:
    type: S3
    buckets:
    - lono-bucket-12di8xz5sy72z
    roleName:
      Ref: IamRole

Files in the the configset files/mygem directory are zipped and uploaded to S3 as part of the lono up process. It’s s3 location is then reference in the template. This spares you from having to upload files manually and updating the template.

authentication as variable

The authentication IAM role can also be set as variable:

config/blueprints/BLUEPRINT/configsets/vars.rb

@authentication = "IamRole"

By design, the @authentication variable takes higher precedence than the value set by authentication "IamRole" method call. This allows more flexilbity to use the configset with templates, as you can use variables to adjust the IAM Role name to match with the template.

authentication as full structure

The authentication can also accept the full structure of AWS::CloudFormation::Authentication resource.

config/blueprints/BLUEPRINT/configsets/vars.rb

@authentication = {
  rolebased: {
    type: "S3",
    buckets: [lono_bucket_name], # lono_bucket_name - helper returns the lono s3 bucket where files are uploaded
    roleName: ref("IamRole"),
  }
}

Back to DSL Docs