AWSTemplateFormatVersion: '2010-09-09' Parameters: KeyName: Description: Name of an existing EC2 KeyPair to enable SSH access Type: 'AWS::EC2::KeyPair::KeyName' LSPName: Description: LSP Name Type: String VPCID: Description: The ID of the VPC in which to create the resources Type: 'AWS::EC2::VPC::Id' LatestAmiId: Type: 'AWS::SSM::Parameter::Value' Default: '/aws/service/canonical/ubuntu/server/jammy/stable/current/amd64/hvm/ebs-gp2/ami-id' Resources: # EC2 Instance EC2Instance: Type: 'AWS::EC2::Instance' Properties: InstanceType: m6a.xlarge ImageId: !Ref LatestAmiId KeyName: !Ref KeyName BlockDeviceMappings: - DeviceName: "/dev/sda1" Ebs: VolumeSize: 1024 VolumeType: gp2 DeleteOnTermination: true UserData: Fn::Base64: !Sub | #!/bin/bash # Elevate privileges if [ "$EUID" -ne 0 ]; then sudo bash "$0" "$@" exit fi # Redirect all outputs to a log file exec > >(tee -a "/tmp/deployment.log") 2>&1 # fix locale if on debian if grep -q "Debian" /etc/os-release; then sed -i '/^# en_US.UTF-8 UTF-8/s/^# //' /etc/locale.gen locale-gen echo "export LC_ALL=en_US.UTF-8" >> /etc/bash.bashrc echo "export LANG=en_US.UTF-8" >> /etc/bash.bashrc fi source /etc/bash.bashrc # create users sudo adduser --disabled-password --gecos "" lightning sudo adduser --disabled-password --gecos "" bitcoin sudo adduser --disabled-password --gecos "" lspd # Create a file to store the credentials CREDENTIALS="/home/lspd/credentials.txt" touch "$CREDENTIALS" # Generate a random password for PostgreSQL users LSPD_DB_PASSWORD=$(> "$CREDENTIALS" echo "postgres lspd:" >> "$CREDENTIALS" echo "username: lspd " >> "$CREDENTIALS" echo "password: $LSPD_DB_PASSWORD" >> "$CREDENTIALS" echo "postgres lightning:" >> "$CREDENTIALS" echo "username: lightning" >> "$CREDENTIALS" echo "password: $LIGHTNING_DB_PASSWORD" >> "$CREDENTIALS" # Generic name if no name is provided (running locally) if [ -z "$LSPName" ]; then LSPName="lsp-$(> "$CREDENTIALS" echo "rpcuser: lnd" >> "$CREDENTIALS" echo "rpcpassword: $RPCPASSWORD" >> "$CREDENTIALS" sudo mkdir /etc/bitcoin/ sudo touch /etc/bitcoin/bitcoin.conf cat <> "$CREDENTIALS" sudo echo "cln hsm_secret backup:" >> "$CREDENTIALS" sudo xxd /home/lightning/.lightning/bitcoin/hsm_secret >> "$CREDENTIALS" # Post install PUBKEY=$(sudo -u lightning lightning-cli getinfo | jq .id | cut -d "\"" -f 2) LSPD_PRIVATE_KEY=$(lspd genkey | awk -F= '{print $2}' | cut -d "\"" -f 2) TOKEN=$(lspd genkey | awk -F= '{print $2}' | cut -d "\"" -f 2) EXTERNAL_IP=$(curl -s http://whatismyip.akamai.com/) echo "### LSPD Credentials ###" >> "$CREDENTIALS" echo "token: $TOKEN" >> "$CREDENTIALS" echo "lspd_private_key: $LSPD_PRIVATE_KEY" >> "$CREDENTIALS" cat <