Skip to content

Instantly share code, notes, and snippets.

@vgorloff
Created November 14, 2022 19:03
Show Gist options
  • Save vgorloff/b25f48e746370111094f4648d414d555 to your computer and use it in GitHub Desktop.
Save vgorloff/b25f48e746370111094f4648d414d555 to your computer and use it in GitHub Desktop.
Setting up AWS DynamoDB Local as macOS autostart service.
  1. Download archive from "https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html"

  2. Unpack it to: /opt/aws/dynamodb

  3. Create shell script: /opt/aws/dynamodb/dynamodb_local.sh.

    #!/bin/bash
    
    RootDirPath=$(cd "$(dirname "$0")"; pwd)
    cd "$RootDirPath"
    
    java -Djava.library.path="$RootDirPath/DynamoDBLocal_lib" -jar "$RootDirPath/DynamoDBLocal.jar" "$@"
  4. Update PATH variable: export PATH="$PATH:/opt/aws/dynamodb"

  5. Run dynamodb_local.sh -help

  6. Run /opt/aws/dynamodb/dynamodb_local.sh -sharedDb -port 6320 -dbPath /opt/mca/dynamodb

  7. Test the instance aws dynamodb list-tables --endpoint-url http://localhost:6320

  8. Create file ~/Library/LaunchAgents/mca.dynamoDBLocal.plist

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Label</key>
        <string>mca.dynamoDBLocal</string>
        <key>LimitLoadToSessionType</key>
        <array>
            <string>Aqua</string>
            <string>Background</string>
            <string>LoginWindow</string>
            <string>StandardIO</string>
            <string>System</string>
        </array>
        <key>ProgramArguments</key>
        <array>
            <string>/opt/aws/dynamodb/dynamodb_local.sh</string>
            <string>-sharedDb</string>
            <string>-port</string>
            <string>6320</string>
            <string>-dbPath</string>
            <string>/opt/mca/dynamodb</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>WorkingDirectory</key>
        <string>/opt/aws/dynamodb</string>
        <key>StandardErrorPath</key>
        <string>/opt/mca/dynamodb/dynamodb-stderr.log</string>
        <key>StandardOutPath</key>
        <string>/opt/mca/dynamodb/dynamodb-stdout.log</string>
    </dict>
    </plist>
  9. Run as macOS service launchctl bootstrap user/`id -u` $HOME/Library/LaunchAgents/mca.dynamoDBLocal.plist

  10. Get status: launchctl print user/`id -u`/mca.dynamoDBLocal

  11. Unload macOS service if not needed anymore: launchctl bootout user/`id -u`/mca.dynamoDBLocal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment