Quick tip of the day: While learning Java, avoid defining anything as static

If you’re just starting out and learning Java, avoid the temptation of defining anything as static until you understand what this modifier does and why/when you need to use it: no static Class properties, no static methods.

The only use of static while you’re starting out is in your main method. You don’t need it anywhere else. You’ll avoid a lot of unexpected and unexplainable behavior as a result.

Getting started with the Mastodon APIs – notifications

The docs for the Mastodon APIs are pretty good, but there’s a surprising lack of working examples online (compared to using the Twitter APIs) which means starting out I’ve been stumped several times already trying to work out how to what seem to be simple things.

Publishing a new status (a ‘Toot’, equivalent in Twitter terms to a ‘Tweet’), is easy enough with POST /statuses . Getting a list of who has mentioned you in a status was not that obvious though.

I took a look at getting my timeline with various options, using GET /timelines, before realizing what I was probably looking for was GET /notifications which can be filtered by various types, including mentions, using

GET /notifications?types[]=mention

Note the types array parameter with [] following the name. I haven’t seen this convention used before, but this is described in the docs here.

Most of the APIs returning statuses look like this:

{
      id: 'unique-id',
      type: 'mention',
      created_at: '2022-11-20T04:46:33.902Z',
      account: {
        // details about the account that posted this status
      },
      status: {
        id: 'unique-id-for-this-status',
        created_at: '2022-11-20T04:46:22.000Z',
        in_reply_to_id: null,
        in_reply_to_account_id: null,
        content: {
          //content of the status here, as HTML
        }

Note that the type=mention here, as this is what we filtered for with the types=[] parameter.

Read AWS IAM permission errors carefully – they tell you everything you need to know (Twitter to Mastodon bot migration)

Migrating my @kevinhookebot Twitter bot to Mastodon, I made some updates to how the Lambda queries a source DynamoDB table for new messages to be posted and ran into this error:

"errorType": "AccessDeniedException",
    "errorMessage": "User: arn:aws:sts::account-id:assumed-role/lambda-kevinhookebot-role/kevinhooketwitterbot-v2-dev-sendTweet is not authorized to perform: dynamodb:Query on resource: arn:aws:dynamodb:us-west-1:account-id:table/tweetbottweets/index/tweetdate-createdate-index because no identity-based policy allows the dynamodb:Query action"

The IAM role I’m reusing does have dynamodb:Query, but only on these resources:

"Resource": [
  "arn:aws:dynamodb:us-west-1:account-id:table/tweetbottweets",
  "arn:aws:dynamodb:us-west-1:account-id:table/tweetbottweets/index/Index",
  "arn:aws:dynamodb:us-west-1:account-id:table/tweetbotreplies"
]

This only includes the table itself, the primary index called Index, and another table tweebotreplies.

Notice this part of the message:

is not authorized to perform: dynamodb:Query on resource: arn:aws:dynamodb:us-west-1:account-id:table/tweetbottweets/index/tweetdate-createdate-index

The issue is this role does not include Query on a new index I added, called tweetdate-createdate-index. To resolve this, add this index to the list of Resources, and problem resolved.