<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abdallah Deeb</title>
    <description>The latest articles on DEV Community by Abdallah Deeb (@abdallah).</description>
    <link>https://dev.to/abdallah</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F87924%2F80da0339-7f6f-4352-90d3-33a5d3c95fa3.jpeg</url>
      <title>DEV Community: Abdallah Deeb</title>
      <link>https://dev.to/abdallah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdallah"/>
    <language>en</language>
    <item>
      <title>I gave a colleague a terminal into one Claude Code session</title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Wed, 11 Nov 2026 11:33:39 +0000</pubDate>
      <link>https://dev.to/abdallah/i-gave-a-colleague-a-terminal-into-one-claude-code-session-375m</link>
      <guid>https://dev.to/abdallah/i-gave-a-colleague-a-terminal-into-one-claude-code-session-375m</guid>
      <description>&lt;p&gt;I'm part of a small infrastructure team, and most days I have a handful of Claude Code sessions running on a few machines. &lt;a href="https://github.com/abdallah/session-hub" rel="noopener noreferrer"&gt;sessionhub&lt;/a&gt; keeps track of them: one registry, one inbox, every machine.&lt;/p&gt;

&lt;p&gt;Sooner or later someone asks: "can I look at that session with you?"&lt;/p&gt;

&lt;p&gt;Until last week my honest answer was "sort of".&lt;/p&gt;

&lt;h2&gt;
  
  
  What I could offer before
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;A screen share.&lt;/strong&gt; They watch, I type. Fine for five minutes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An SSH account.&lt;/strong&gt; This is the real answer most teams give, and it is the wrong size. An account on my machine shows every pane I have open, every other session, my shell history, and my files. They wanted one conversation. I would be handing over the building to show them one room.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The dashboard.&lt;/strong&gt; sessionhub already had a web dashboard, so the first step was a guest link:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sessionhub login --name alice --session 3f2a9c10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That prints a one-time link. The browser that opens it sees that one session and nothing else. It can read it, reply to it, and answer its permission prompts and questions. It gets no other session, no tasks, no resume command, no Remote Control link. Every other route answers &lt;code&gt;403&lt;/code&gt;, and I take it back with &lt;code&gt;sessionhub login rm alice&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That covered reading and answering. It was OK for a couple of days, then it wasn't. It did not cover the thing people ask for when they say "let me drive for a minute": the terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  sessionhub attach
&lt;/h2&gt;

&lt;p&gt;So the same link now works in a terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sessionhub attach https://hub.example.com/login/&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;code&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The guest's machine doesn't join anything. The command signs in with the link, shows that one session's terminal, and sends keystrokes to it. &lt;code&gt;Ctrl-]&lt;/code&gt; detaches, and the session keeps running.&lt;/p&gt;

&lt;p&gt;There is no SSH and no inbound port. The shape is the one the rest of sessionhub already uses: machines poll the server, and the server never connects out to them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;guest terminal ──HTTP──&amp;gt; sessionhub server &amp;lt;──HTTP── machine watcher ──&amp;gt; the pane
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each side holds one streaming GET for bytes coming toward it and makes small POSTs for bytes going away. The server relays between them in memory. I skipped WebSockets: Go's standard library has no WebSocket server, and sessionhub has four direct dependencies that I'd like to keep at four. Two chunked HTTP streams do the job with &lt;code&gt;net/http&lt;/code&gt; alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trade-off I took
&lt;/h2&gt;

&lt;p&gt;The mirror is a snapshot, not a real terminal stream. The watcher reads the pane's screen every 250 ms and sends a fresh frame when it changed. That means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The guest sees the host pane's size, not their own.&lt;/li&gt;
&lt;li&gt;No scrollback on the guest's side.&lt;/li&gt;
&lt;li&gt;A fast-scrolling build log looks choppy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a Claude Code session that is fine. The screen changes in bursts, and what the guest needs is the current state and a keyboard. A proper stream is a later change behind the same command.&lt;/p&gt;

&lt;p&gt;One thing to be straight about: attaching gives the guest Claude's keyboard, and that includes &lt;code&gt;!&lt;/code&gt; shell commands. The link is scoped to one session, but that session runs as me. Hand it only to someone you would give a shell. The link is one-time, the sign-in expires, and an attach ends after 30 minutes without traffic.&lt;/p&gt;

&lt;h2&gt;
  
  
  A second terminal: Rex
&lt;/h2&gt;

&lt;p&gt;Everything above first worked through &lt;a href="https://herdr.dev" rel="noopener noreferrer"&gt;herdr&lt;/a&gt;, the terminal multiplexer I run sessions in. This week I added &lt;a href="https://www.superlogical.com/rex" rel="noopener noreferrer"&gt;Rex&lt;/a&gt; as a second backend, using only its &lt;code&gt;rex&lt;/code&gt; CLI:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sessionhub start &amp;lt;machine&amp;gt;&lt;/code&gt; opens a new Rex session running Claude with Remote Control on.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sessionhub resume &amp;lt;id&amp;gt;&lt;/code&gt; focuses the block that runs a session.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sessionhub move &amp;lt;id&amp;gt; &amp;lt;machine&amp;gt;&lt;/code&gt; carries a session between machines, herdr or Rex on either side.&lt;/li&gt;
&lt;li&gt;A watcher runs as a systemd unit on a machine with no herdr at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Status, plainly: start, resume, and Remote Control are tested live on Linux. Moves into Rex pass against a fake so far, and macOS is untested.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I took from it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scope the access to the question.&lt;/strong&gt; "Can I see that session?" deserves one session, not a machine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reuse the direction of trust you already have.&lt;/strong&gt; Machines polling the server made a relay possible with no new open port.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ship the snapshot.&lt;/strong&gt; The 250 ms mirror took a fraction of the work of a real stream, and it answers the request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;sessionhub is open source (MIT), a single Go binary with SQLite: &lt;a href="https://github.com/abdallah/session-hub" rel="noopener noreferrer"&gt;github.com/abdallah/session-hub&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>go</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Teaching Claude Code to message my colleagues in my own voice</title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Fri, 06 Nov 2026 13:13:38 +0000</pubDate>
      <link>https://dev.to/abdallah/teaching-claude-code-to-message-my-colleagues-in-my-own-voice-1f0o</link>
      <guid>https://dev.to/abdallah/teaching-claude-code-to-message-my-colleagues-in-my-own-voice-1f0o</guid>
      <description>&lt;p&gt;I'm part of a small infrastructure team, and a surprising amount of my day is short messages: "can you look at this MR", "is staging free", "did the migration finish". I already work with Claude Code most of the day, so I wanted it to send those messages for me.&lt;/p&gt;

&lt;p&gt;The first drafts were the problem. I'd ask for a one-line question, and the agent would write five paragraphs: what the MR changes, why, which files it touches, the risks, a bulleted list of "key considerations", and a closing "let me know if you have any questions!" Every word was accurate, and nobody read it. It was too long and too technical, and it looked like AI slop, so people skimmed past it or left it for later. A question my colleagues would have answered in a minute sat there for hours.&lt;/p&gt;

&lt;p&gt;What I needed was the message I would have typed myself: "can you check the staging plan on !885 when you get a minute? no rush".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2ief34glw9qqtq241dq7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2ief34glw9qqtq241dq7.png" alt="The agent's long, technical draft next to the one-line message I would have written" width="799" height="323"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I wrote &lt;a href="https://github.com/abdallah/mattermost-dm" rel="noopener noreferrer"&gt;mattermost-dm&lt;/a&gt;, an agent skill and a small Python script that sends Mattermost DMs as you. Sending is the easy part. Most of the skill is about making the messages sound like the person who sends them.&lt;/p&gt;

&lt;h2&gt;
  
  
  A style guide for one person
&lt;/h2&gt;

&lt;p&gt;The skill reads a file called &lt;code&gt;voice.md&lt;/code&gt; before it drafts anything. It's a short style guide, written about you, for the agent. The template covers the habits that make a message recognisably yours:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Length:&lt;/strong&gt; one line, or two or three short ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Capitals and punctuation:&lt;/strong&gt; sentence case or all lowercase, a full stop at the end or not.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asks:&lt;/strong&gt; "can you … please?", "when you have a minute, …".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Warmth:&lt;/strong&gt; "thanks!", a smiley now and then, or none at all.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Words you use often:&lt;/strong&gt; "btw", "FYI".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Links and tickets:&lt;/strong&gt; a bare URL, or a linked ticket number followed by its title.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't:&lt;/strong&gt; the things you never do, like formal sign-offs, long explanations, or bold.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The template also asks for one example of a first message of the day, because a single example shows the shape faster than any list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;good morning

can you check the staging plan on !885 when you get a minute? no rush
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The "Don't" list does the most work against slop. Agents add things: background nobody asked for, bullet points, bold, a summary of what they just asked, a "let me know if you have any questions". The guide says what you never write, so the agent knows what to leave out.&lt;/p&gt;

&lt;p&gt;The skill also has a few rules of its own, whatever your voice: lead with what you need, then add one or two lines of context at most. Don't invent dates or promises, and don't use review-speak like "the part worth your eyes". Always link a ticket or MR, so the reader can click through for the detail.&lt;/p&gt;

&lt;p&gt;Git ignores &lt;code&gt;voice.md&lt;/code&gt;, so it stays on your machine. Without it, the skill falls back to short, friendly, plain messages, written like a note to a teammate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learning the voice from your own messages
&lt;/h2&gt;

&lt;p&gt;Writing a style guide about yourself is hard, because you don't notice your own habits. The faster route is to let Claude Code read how you actually write.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mm-dm --history &amp;lt;person&amp;gt; --days 90&lt;/code&gt; prints your DM with one person. The README suggests this prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Run mm-dm --history &amp;lt;name&amp;gt; --days 90 for each of these people: &amp;lt;names&amp;gt;.
Learn only from messages I wrote. Draft voice.md from voice.example.md. Describe my habits for
length, capitals, punctuation, greetings, asks, warmth, common words and links, and what I never
do. Copy my habits, not my typos. Don't include real names, projects, clients or quoted messages.
Show me the draft before you save it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few lines in that prompt carry most of the weight:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Three to five people, across different kinds of work.&lt;/strong&gt; You write differently to a close teammate than to someone in another department, and the guide should cover both.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"Copy my habits, not my typos."&lt;/strong&gt; Without this line, the agent faithfully reproduces your mistakes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No real names or quoted messages.&lt;/strong&gt; The guide describes patterns with invented examples, so it doesn't turn into a copy of your private conversations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then read the draft and fix anything that doesn't sound like you. Ask for a few test messages and adjust the file until you'd send them without editing.&lt;/p&gt;

&lt;p&gt;There's a trade-off to know about: &lt;code&gt;--history&lt;/code&gt; prints both sides of each conversation, so your colleagues' messages reach your AI provider while the guide is drafted. Check your company's policy and choose conversations with nothing confidential in them. If that isn't possible, write &lt;code&gt;voice.md&lt;/code&gt; by hand from the template.&lt;/p&gt;

&lt;h2&gt;
  
  
  Greetings are part of the voice
&lt;/h2&gt;

&lt;p&gt;Voice isn't only wording; it's also rhythm. Nobody says "good morning" to someone they messaged ten minutes ago, and nobody skips a greeting after a week of silence.&lt;/p&gt;

&lt;p&gt;Messages start with a &lt;code&gt;{hi}&lt;/code&gt; placeholder, and the script fills it in from your real history. It asks Mattermost when you last posted in that DM. If you haven't spoken today, or it's been more than 4 hours, &lt;code&gt;{hi}&lt;/code&gt; becomes a greeting. Otherwise it disappears, along with the blank line after it. In a batch, this happens separately for each person.&lt;/p&gt;

&lt;p&gt;The greetings themselves are yours too. Add your own lists to &lt;code&gt;~/.mattermost&lt;/code&gt;, one for the morning and one for the afternoon:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;MM_DM_GREETINGS_AM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"good morning|morning :)"&lt;/span&gt;
&lt;span class="nv"&gt;MM_DM_GREETINGS_PM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"hi there|hey|good afternoon"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The script picks one per person per day and keeps it, so you don't greet the same person three different ways in one morning.&lt;/p&gt;

&lt;p&gt;Batches use &lt;code&gt;{first_name}&lt;/code&gt;, so a question to five reviewers still reads as five personal messages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{hi} {first_name}

can you review the runbook change before Friday's maintenance?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  You still see every message
&lt;/h2&gt;

&lt;p&gt;A good voice makes approval quick, but it doesn't replace it. Every message goes through a preview first: &lt;code&gt;mm-dm --dry-run&lt;/code&gt; renders each message, greeting and name included, and Claude shows them to you. When you say yes, &lt;code&gt;mm-dm --send-pending&lt;/code&gt; sends exactly what the preview printed. It doesn't take new text, so nothing gets reworded after you've read it. Each preview sends once, and it expires after an hour.&lt;/p&gt;

&lt;p&gt;The token stays out of the conversation as well. The script reads it from &lt;code&gt;~/.mattermost&lt;/code&gt; and never prints it, and the skill tells Claude not to open that file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/abdallah/mattermost-dm.git ~/.claude/skills/mattermost-dm
&lt;span class="nb"&gt;touch&lt;/span&gt; ~/.mattermost &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;chmod &lt;/span&gt;600 ~/.mattermost
&lt;span class="nb"&gt;cp&lt;/span&gt; ~/.claude/skills/mattermost-dm/voice.example.md ~/.claude/skills/mattermost-dm/voice.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add your server and a personal access token (&lt;strong&gt;Profile &amp;gt; Security &amp;gt; Personal Access Tokens&lt;/strong&gt;) to &lt;code&gt;~/.mattermost&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;MM_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://chat.example.com
&lt;span class="nv"&gt;MM_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then edit &lt;code&gt;voice.md&lt;/code&gt;, or ask Claude Code to draft it from your history. It needs Python 3.9 or later and has no other dependencies. If you use more than one machine, copy &lt;code&gt;voice.md&lt;/code&gt; to each one yourself, because Git doesn't sync it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Beyond Mattermost
&lt;/h2&gt;

&lt;p&gt;The script is specific to Mattermost, but the idea isn't. Any agent that writes as you, whether it's emails, ticket comments, or commit messages, benefits from a short, private file that describes how you write and, more importantly, what you never write. Draft it from your own messages, then correct it until the test messages sound right.&lt;/p&gt;

&lt;p&gt;The code is MIT licensed: &lt;a href="https://github.com/abdallah/mattermost-dm" rel="noopener noreferrer"&gt;github.com/abdallah/mattermost-dm&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>mattermost</category>
      <category>productivity</category>
    </item>
    <item>
      <title>I built an inbox for my Claude Code sessions. Then I never checked it.</title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Sun, 25 Oct 2026 15:27:12 +0000</pubDate>
      <link>https://dev.to/abdallah/i-built-an-inbox-for-my-claude-code-sessions-then-i-never-checked-it-hi8</link>
      <guid>https://dev.to/abdallah/i-built-an-inbox-for-my-claude-code-sessions-then-i-never-checked-it-hi8</guid>
      <description>&lt;p&gt;Three weeks ago I wrote about &lt;a href="https://dev.to/abdallah/one-inbox-for-every-claude-code-session-on-every-machine-2en4"&gt;sessionhub&lt;/a&gt;: one registry and one inbox for every Claude Code session on every machine I use. The hub itself took off. I have it open all day to see what's running where, and sessions register, report and move between machines without me thinking about it.&lt;/p&gt;

&lt;p&gt;The inbox is a different story. I stopped looking at it.&lt;/p&gt;

&lt;p&gt;Not because it broke. Because nothing in it told me what to do. A list of sessions marked "blocked" or "done" is information, not an action. If I still had to SSH into the machine to do anything about it, I'd go straight to the terminal and skip the inbox.&lt;/p&gt;

&lt;p&gt;This post is about the changes that turned the inbox from something I could check into something I act from.&lt;/p&gt;

&lt;h2&gt;
  
  
  The question I couldn't answer
&lt;/h2&gt;

&lt;p&gt;I went through the database to see what the inbox had actually caught. Since October 3, Claude Code had raised 171 permission prompts across my machines. &lt;strong&gt;120 of them were not permissions at all. They were Claude asking me a question&lt;/strong&gt; (the &lt;code&gt;AskUserQuestion&lt;/code&gt; tool: "Which approach?", "Should I also update the docs?").&lt;/p&gt;

&lt;p&gt;The hub could show those questions. It could not answer them. "Allow" from the dashboard approved the tool call and answered nothing, so the dialog stayed open in the terminal. All 120 were answered locally.&lt;/p&gt;

&lt;p&gt;Claude Code hooks can answer a question on your behalf: return &lt;code&gt;allow&lt;/code&gt; together with &lt;code&gt;updatedInput&lt;/code&gt;, which is the original tool input plus an &lt;code&gt;answers&lt;/code&gt; map from question text to the chosen label. sessionhub's permission hook was already sitting in that exact spot, waiting for a decision from the server. So the change was small:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The dashboard shows each question's options as buttons, plus an &lt;strong&gt;Other&lt;/strong&gt; box.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Send answer&lt;/strong&gt; posts the choice to the server with the decision.&lt;/li&gt;
&lt;li&gt;The hook hands it back to Claude Code as &lt;code&gt;updatedInput&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F22hl9gritfxi0maapdk2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F22hl9gritfxi0maapdk2.png" alt="A question from Claude in the inbox, with its three options as 0" width="716" height="952"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"hookSpecificOutput"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"hookEventName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"PermissionRequest"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"decision"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"behavior"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"updatedInput"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"questions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"answers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"Which colour?"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Blue"&lt;/span&gt;&lt;span class="p"&gt;}}}}}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first live test failed. My phone tapped the old &lt;strong&gt;Allow&lt;/strong&gt; button, because it was still running the page from before the deploy. So now every API response carries a fingerprint of the page, and an open tab shows a &lt;strong&gt;Reload&lt;/strong&gt; bar when it changes. The server also refuses a plain allow on a question, so a stale page fails loudly instead of quietly doing nothing.&lt;/p&gt;

&lt;p&gt;The second test worked: I tapped "Blue" on my phone and the session carried on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Replying without opening a terminal
&lt;/h2&gt;

&lt;p&gt;The other half of "act from the inbox" is answering a session that finished and asked something in its last message. Each inbox row now has a reply box. sessionhub already had a way to type a message into a session's pane when it's idle (the watcher or the Claude Code mod delivers it), so the reply box reuses that. The draft survives the page's 30-second refresh.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy7p1l4ov4cph8jpcrf4c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy7p1l4ov4cph8jpcrf4c.png" alt="An inbox row waiting on two answers, with a reply box" width="716" height="514"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inbox rows also show the start of Claude's last reply now, Markdown stripped and line breaks kept, instead of the word "Finished". That one change made rows readable at a glance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Moving a session when its machine is off
&lt;/h2&gt;

&lt;p&gt;sessionhub can move a session between machines: pack the transcript and the uncommitted work, seal it for the target, and resume it there. Yesterday I tried to move one between machines while the source was unreachable, so nothing could pack it, and the move failed. The only sign was a line under the session's details.&lt;/p&gt;

&lt;p&gt;Two fixes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Failed moves are an inbox group&lt;/strong&gt; of their own, with a retry button, and they show up in the alerts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Snapshots.&lt;/strong&gt; Each machine's watcher snapshots its idle sessions in the background, at most every 10 minutes and only when the transcript changed. Each snapshot is sealed with X25519 for each other machine, so the server stores blobs it cannot read. If the source machine hasn't polled for 2 minutes, a move uses the latest snapshot instead of waiting. When the source comes back, it ends the leftover pane.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Snapshots are removed when the session ends or moves, after 14 days, or oldest first past 1 GiB.&lt;/p&gt;

&lt;h2&gt;
  
  
  The dashboard, from a human's point of view
&lt;/h2&gt;

&lt;p&gt;I asked Claude Code for a UX review of the live dashboard. It took screenshots at phone and desktop width with headless Chrome through Playwright, read them, and listed what a person would trip over. The fixes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One colour and one icon per state&lt;/strong&gt;: ✋ needs you, 🚚 move failed, 💬 waiting, ⚠️ machine silent, ⏳ working, ✅ finished, 💤 idle.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sorted by state&lt;/strong&gt;, so whatever needs me is on top.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rename&lt;/strong&gt; a session from the web, and fall back to the task's name when the title is the default "Claude Code".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Machine headers say "online" or "silent 8m"&lt;/strong&gt;, which is how I found out one of my machines had dropped off the network.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fem4409t5wqh1q0ru93md.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fem4409t5wqh1q0ru93md.png" alt="Sessions on two machines, each with a coloured state badge" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Tasks: a standup and a place to park ideas
&lt;/h2&gt;

&lt;p&gt;sessionhub turns worklog notes into a daily task list. I never used that tab. When I thought about why, I found two jobs it should be doing:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The standup I write.&lt;/strong&gt; The Tasks tab now has a &lt;strong&gt;Standup&lt;/strong&gt; button: yesterday (the last day with work, so Monday covers Friday), today, and blockers, as plain text with a &lt;strong&gt;Copy&lt;/strong&gt; button. &lt;code&gt;sessionhub task standup&lt;/code&gt; prints the same thing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parking ideas.&lt;/strong&gt; I switch contexts many times a day, and ideas that arrive mid-task get lost. Now there's a "Park an idea" box, a &lt;code&gt;sessionhub idea "…"&lt;/code&gt; command, and any Claude session will park one if I ask. Ideas wait in their own list until I start them or drop them, and they stay out of the standup.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftgsuscerjm1ply4lqw6y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftgsuscerjm1ply4lqw6y.png" alt="The standup text, ready to copy" width="716" height="956"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The tab itself went from a wall of cards to one line per task: open work first, then ideas, then done.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq35ypt834xppvaqfixdl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq35ypt834xppvaqfixdl.png" alt="The Tasks page: open work and ideas on the left, done on the right" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A dashboard you read is not a dashboard you use.&lt;/strong&gt; Every change above removed one trip to a terminal.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Look at the data before the design.&lt;/strong&gt; "Most prompts are questions" was not something I'd have guessed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test on the device you'll use.&lt;/strong&gt; The bug that mattered was a stale page on my phone, not anything a unit test would catch.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;sessionhub is open source (MIT), a single Go binary with SQLite: &lt;a href="https://github.com/abdallah/session-hub" rel="noopener noreferrer"&gt;github.com/abdallah/session-hub&lt;/a&gt;. If you run Claude Code on more than one machine, I'd like to hear what you'd want from it.&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>go</category>
      <category>opensource</category>
    </item>
    <item>
      <title>One inbox for every Claude Code session on every machine</title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Sun, 04 Oct 2026 10:40:28 +0000</pubDate>
      <link>https://dev.to/abdallah/one-inbox-for-every-claude-code-session-on-every-machine-2en4</link>
      <guid>https://dev.to/abdallah/one-inbox-for-every-claude-code-session-on-every-machine-2en4</guid>
      <description>&lt;p&gt;On a normal day I have somewhere between five and fifteen Claude Code sessions running. Some are on my laptop, some on a desktop, a few on a home server that never sleeps. They run inside &lt;a href="https://herdr.dev" rel="noopener noreferrer"&gt;herdr&lt;/a&gt;, an agent-aware terminal multiplexer, and I attach to them over SSH from whatever I'm holding at the time, which is often a phone.&lt;/p&gt;

&lt;p&gt;That setup works well until you step away. Then three questions start nagging:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Which sessions exist right now, and which are still alive?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What has each one done, what is it doing, and is it waiting on me?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;How do I get back into the one that needs me, from wherever I am?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of the tools I already had answered all three. So I built a small thing that does. It's called &lt;strong&gt;sessionhub&lt;/strong&gt;, it's open source (MIT), and this post is about why it exists, how it works, and how you can run it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7y99avauz8c2nvo212jq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7y99avauz8c2nvo212jq.png" alt="The sessionhub dashboard on a phone: sessions grouped by machine, and the inbox with a permission prompt waiting" width="800" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: every tool knows one machine, or one session
&lt;/h2&gt;

&lt;p&gt;I want to be fair to the tools I use every day, because they're good at what they do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;herdr&lt;/strong&gt; knows every agent on &lt;em&gt;its&lt;/em&gt; machine and whether it's working, blocked, or done. It doesn't know about my other machines, and it knows &lt;em&gt;state&lt;/em&gt;, not &lt;em&gt;meaning&lt;/em&gt;: "blocked" doesn't tell me blocked on what.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Claude Code's own session list&lt;/strong&gt; is per machine too. Great for resuming on the box you're sitting at; no help for the session on the server in the other room.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remote Control&lt;/strong&gt; gives a single session a link I can open in the Claude app. Excellent, but I have to turn it on per session, and I first need to know &lt;em&gt;which&lt;/em&gt; session to turn it on for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSH plus tmux-style multiplexers&lt;/strong&gt; get me into a machine. Then I'm hunting through panes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What was missing wasn't another terminal. It was a &lt;strong&gt;registry&lt;/strong&gt;: one place that knows every session on every machine, what each one is working on in plain words, and what each one needs from me.&lt;/p&gt;

&lt;h2&gt;
  
  
  What sessionhub does
&lt;/h2&gt;

&lt;p&gt;sessionhub is one static Go binary with a SQLite database. The same binary is the server and every client. You run the server on one always-on machine and "join" each machine that runs Claude Code.&lt;/p&gt;

&lt;p&gt;From there:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Registry.&lt;/strong&gt; Every session on every joined machine shows up with its machine, directory, branch, title, and status: &lt;code&gt;live&lt;/code&gt;, &lt;code&gt;blocked&lt;/code&gt;, &lt;code&gt;stale&lt;/code&gt;, or &lt;code&gt;ended&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inbox.&lt;/strong&gt; The sessions that need you, across all machines: blocked on a permission prompt, waiting on an answer, or finished a turn you haven't looked at.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remote approvals.&lt;/strong&gt; Allow or deny a waiting permission prompt from the dashboard or the CLI. The prompt still shows in the terminal, and whichever answer comes first wins. It never adds an "always allow" rule.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Progress reports.&lt;/strong&gt; Each session gets an MCP tool to report what it has done, what's in flight, and what it's waiting on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Get back in.&lt;/strong&gt; &lt;code&gt;sessionhub resume &amp;lt;id&amp;gt;&lt;/code&gt; focuses the pane, restarts the session, or prints the exact &lt;code&gt;ssh&lt;/code&gt; command for the machine it's on. Or turn on Remote Control and continue in the Claude app.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Standing rules and messages.&lt;/strong&gt; Add a rule once and every session sees it with every prompt. Type a message into one session, or into all of them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Move sessions.&lt;/strong&gt; Hand a session, with its branch and uncommitted changes, to another machine or to a Claude Code cloud session.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start new sessions.&lt;/strong&gt; Pick a machine and a directory on the dashboard, and a new Claude session starts there with Remote Control on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Alerts.&lt;/strong&gt; An optional Telegram message when a session has been blocked or waiting on you for 30 seconds.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's the inbox on a phone, with a session asking to run &lt;code&gt;npm install&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjfq1il1wfxkh5ac3pb9y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjfq1il1wfxkh5ac3pb9y.png" alt="The inbox: a blocked session asks to use Bash for npm install, with Allow once and Deny buttons" width="800" height="1240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How it fits together
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl4h1l1dxszkkak2si6dm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl4h1l1dxszkkak2si6dm.png" alt="Architecture: Claude Code hooks, the MCP server, and an optional herdr watcher on each machine report to one sessionhub server; you use the dashboard, the CLI, or Telegram" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are three ways a session talks to the hub, and you can use any of them:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Claude Code hooks.&lt;/strong&gt; &lt;code&gt;sessionhub install-hooks&lt;/code&gt; adds entries to &lt;code&gt;~/.claude/settings.json&lt;/code&gt; (it backs the file up first, and only ever touches its own entries). Most are async, so they never slow a prompt down (paths shortened):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"SessionStart"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"~/.local/bin/sessionhub hook session-start"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"async"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"~/.local/bin/sessionhub hook context"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"timeout"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"UserPromptSubmit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"~/.local/bin/sessionhub hook prompt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"async"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"~/.local/bin/sessionhub hook context"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"timeout"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]}]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;context&lt;/code&gt; hook is synchronous on purpose: its output is how the standing rules reach the prompt. It reads a local copy of the rules and never touches the network, so a prompt never waits on the hub.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. An MCP server.&lt;/strong&gt; &lt;code&gt;sessionhub mcp&lt;/code&gt; gives each session &lt;code&gt;report_progress&lt;/code&gt; and &lt;code&gt;set_title&lt;/code&gt;. A short snippet in &lt;code&gt;~/.claude/CLAUDE.md&lt;/code&gt; tells Claude when to use them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;## Reporting progress to sessionhub&lt;/span&gt;
&lt;span class="p"&gt;
-&lt;/span&gt; Call &lt;span class="sb"&gt;`report_progress`&lt;/span&gt; when you finish a task, when you start a task that
  will take a while, and when you are blocked waiting on me or on something
  external. Fill &lt;span class="sb"&gt;`done`&lt;/span&gt;, &lt;span class="sb"&gt;`in_flight`&lt;/span&gt;, and &lt;span class="sb"&gt;`waiting_on`&lt;/span&gt; with short one-line items.
&lt;span class="p"&gt;-&lt;/span&gt; Call &lt;span class="sb"&gt;`set_title`&lt;/span&gt; once the session has a clear purpose, and again if the
  purpose changes.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's what turns "blocked" into "waiting on: permission to run npm install".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. A herdr plugin (optional).&lt;/strong&gt; If you use herdr, its plugin registers the sessions in your panes, ends them when the pane closes, and runs a small watcher. The watcher is what lets the hub &lt;em&gt;do&lt;/em&gt; things on a machine: type a message, turn on Remote Control, move a session, or start a new one.&lt;/p&gt;

&lt;h3&gt;
  
  
  The rule I cared about most: fail open
&lt;/h3&gt;

&lt;p&gt;A tool that watches your agents must never become the reason they stall. So every client fails open. Hooks always exit 0. Every call from a hook or the MCP server has a two-second limit. If the server is down, writes go to a local queue (&lt;code&gt;~/.local/state/sessionhub/queue.jsonl&lt;/code&gt;) and drain later. Claude Code and herdr never wait on sessionhub.&lt;/p&gt;

&lt;h3&gt;
  
  
  The server never connects to your machines
&lt;/h3&gt;

&lt;p&gt;Machines poll the server; the server never reaches into them. When you tap &lt;strong&gt;Allow once&lt;/strong&gt; on your phone, the &lt;code&gt;PermissionRequest&lt;/code&gt; hook on that machine is holding a long poll open, and it picks up your answer. When you start a new session, the machine's watcher is long-polling for work and claims the request. That keeps the firewall story simple: the only open port is the hub's.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using it
&lt;/h2&gt;

&lt;p&gt;The CLI is where I spend most of my time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sessionhub ls
MACHINE  ID        TITLE                     STATUS   AGE  REPORT
tower    e5b07a1c  postgres 16 upgrade plan  live     1s   doing: writing the rollback steps
bluebox  c18e5f43  rewrite the quickstart    live     1s   waiting: your review of the wording
bluebox  a72d4b90  dark mode for settings    blocked  1s   doing: settings page
tower    3f9c1e27  fix CI token rotation     live     1s   doing: re-running the pipeline

$ sessionhub inbox
Blocked (1)
  a72d4b90  dark mode for settings  bluebox  1s  asks to use Bash: npm install

Waiting on you (1)
  c18e5f43  rewrite the quickstart  bluebox  1s  your review of the wording
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;sessionhub show&lt;/code&gt; gives the full picture for one session, including its report history:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sessionhub show a72d
title:     dark mode for settings
machine:   bluebox
state:     blocked
branch:    dark-mode
resume:    ssh -t bluebox '~/.local/bin/sessionhub resume a72d4b90-...'

reports (1, newest first)
    done        theme tokens
    in flight   settings page
    waiting on  permission to run npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few more I use daily:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sessionhub approve a72d                          &lt;span class="c"&gt;# allow that npm install once (asks first)&lt;/span&gt;
sessionhub rules add &lt;span class="s2"&gt;"Never push to main."&lt;/span&gt;       &lt;span class="c"&gt;# every session sees it, on every prompt&lt;/span&gt;
sessionhub send &lt;span class="nt"&gt;--machine&lt;/span&gt; tower &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Wrap up and report progress."&lt;/span&gt;
sessionhub move c18e bluebox                     &lt;span class="c"&gt;# conversation, branch and uncommitted changes&lt;/span&gt;
sessionhub start tower &lt;span class="nt"&gt;--dir&lt;/span&gt; ~/Code/api &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Fix the flaky test in ci.yml"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That last one is the newest feature, and it's the one I wanted most. On the dashboard it's a &lt;strong&gt;New session&lt;/strong&gt; button: pick a machine and a directory (it suggests the ones you've used), optionally type a first prompt, and you get an &lt;strong&gt;Open in Claude&lt;/strong&gt; link a few seconds later:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbecb3cgjww72ksz6gyud.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbecb3cgjww72ksz6gyud.png" alt="The New session panel: machine tower, directory ~/Code/api, and an Open in Claude link after the start" width="800" height="1520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now I can start work on my home server from a train.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trying it in five minutes
&lt;/h2&gt;

&lt;p&gt;You can run the server and a client on one machine to see what it does:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Install the latest release (Linux or macOS, amd64 or arm64) into ~/.local/bin:&lt;/span&gt;
curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://raw.githubusercontent.com/abdallah/session-hub/main/install.sh | sh

&lt;span class="c"&gt;# This machine holds the server:&lt;/span&gt;
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; ~/.config/sessionhub
&lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; 600 /dev/null ~/.config/sessionhub/server.toml
sessionhub server &amp;amp;

&lt;span class="c"&gt;# Join it: creates a token, installs the hooks and the MCP server.&lt;/span&gt;
sessionhub &lt;span class="nb"&gt;join &lt;/span&gt;localhost &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;hostname&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# Start claude anywhere, send a prompt, then:&lt;/span&gt;
sessionhub &lt;span class="nb"&gt;ls
&lt;/span&gt;sessionhub login &lt;span class="nt"&gt;--name&lt;/span&gt; my-phone   &lt;span class="c"&gt;# a one-time sign-in link for the dashboard&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more machines, run the server on an always-on box (there's a systemd unit and a &lt;code&gt;docker-compose.yml&lt;/code&gt;), put it behind a tunnel or reverse proxy, and &lt;code&gt;sessionhub join&lt;/code&gt; each machine. The &lt;a href="https://github.com/abdallah/session-hub/blob/main/docs/self-hosting.md" rel="noopener noreferrer"&gt;self-hosting guide&lt;/a&gt; walks through it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A word on security
&lt;/h2&gt;

&lt;p&gt;Be honest with yourself about what this server can do. A machine token or a signed-in browser can approve tool calls, add rules that every session reads, type messages into sessions, and start new ones. That's the point of the tool, and it also means &lt;strong&gt;a leaked credential can get Claude to run commands on your machines.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So: keep the server on a private network if you can, use HTTPS if you expose it, turn on the Telegram alerts (they also fire whenever someone adds a rule), and use the per-machine opt-outs (&lt;code&gt;remote_permissions = false&lt;/code&gt;, &lt;code&gt;remote_start = false&lt;/code&gt;) on machines you want to keep hands-off. &lt;a href="https://github.com/abdallah/session-hub/blob/main/SECURITY.md" rel="noopener noreferrer"&gt;SECURITY.md&lt;/a&gt; has a table of what each credential can do.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it was built
&lt;/h2&gt;

&lt;p&gt;I built sessionhub with Claude Code itself, which turned out to be a good test of the tool and of the process.&lt;/p&gt;

&lt;p&gt;Every feature started as a short spec, then a plan broken into tasks, and each task had to meet a written definition of done before it counted. Two rules from that list did most of the work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Don't invent APIs.&lt;/strong&gt; Claude Code hook payloads and herdr events come from captured real payloads in &lt;code&gt;testdata/&lt;/code&gt;, never from memory. The spec said it bluntly: verify against &lt;code&gt;--help&lt;/code&gt; and the docs, and quote what you found.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tests walk the whole path.&lt;/strong&gt; Each one checks the start state, acts, asserts what must &lt;em&gt;not&lt;/em&gt; have happened as well as what must, and reads the result back the way you would see it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The early plan was to host it on Cloud Run. An always-on instance came out at about $45–50 a month, so it moved to a systemd user service on a home server behind a Cloudflare Tunnel, which costs nothing extra.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;sessionhub is a personal, single-user tool: one person, their machines, no accounts or teams. That's deliberate, and I don't plan to change it. Things I do want:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a Claude Code plugin, so the hooks, MCP server and CLAUDE.md snippet install in one step;&lt;/li&gt;
&lt;li&gt;cloud sessions reporting in, so the claude.ai/code sessions show up next to the local ones.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you run more than a couple of Claude Code sessions across more than one machine, I'd love to hear whether this matches your workflow, and where it doesn't.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Repo:&lt;/strong&gt; &lt;a href="https://github.com/abdallah/session-hub" rel="noopener noreferrer"&gt;https://github.com/abdallah/session-hub&lt;/a&gt; (MIT, Linux and macOS binaries on the releases page)&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>ai</category>
      <category>go</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Why I Built a New Memory Plugin for Hermes Agent</title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Sun, 14 Jun 2026 18:17:11 +0000</pubDate>
      <link>https://dev.to/abdallah/why-i-built-a-new-memory-plugin-for-hermes-agent-467n</link>
      <guid>https://dev.to/abdallah/why-i-built-a-new-memory-plugin-for-hermes-agent-467n</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/NousResearch/hermes-agent" rel="noopener noreferrer"&gt;Hermes Agent&lt;/a&gt; already has memory, and that matters.&lt;/p&gt;

&lt;p&gt;It keeps local context, it improves over time, and it works without forcing you into a cloud service. It also supports several external memory providers.&lt;/p&gt;

&lt;p&gt;I still built &lt;a href="https://github.com/abdallah/hermes-mempalace" rel="noopener noreferrer"&gt;hermes-mempalace&lt;/a&gt;, because none of the existing options fit my setup quite right.&lt;/p&gt;

&lt;p&gt;I wanted something:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;local-first&lt;/li&gt;
&lt;li&gt;isolated by Hermes profile&lt;/li&gt;
&lt;li&gt;verbatim, not just extracted facts&lt;/li&gt;
&lt;li&gt;easy to inspect on disk&lt;/li&gt;
&lt;li&gt;simple enough to trust over time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That last part is the important one. I did not want a memory layer that turns conversations into an opaque pile of embeddings or summaries you cannot really audit. I wanted actual transcripts, mined into a readable structure, with no hidden server in the middle.&lt;/p&gt;

&lt;p&gt;Why the existing options were not enough&lt;/p&gt;

&lt;p&gt;Hermes already gives you a few paths:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;built-in memory and session context&lt;/li&gt;
&lt;li&gt;external providers for different use cases&lt;/li&gt;
&lt;li&gt;enough flexibility to adapt, if you are willing to bend your workflow around them&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And to be clear, some of those options are good.&lt;/p&gt;

&lt;p&gt;But ... I run Hermes on a headless machine at home. And I use separate profiles for different contexts. And I do not want conversation content depending on a cloud API or a separate service unless there is a very good reason.&lt;/p&gt;

&lt;p&gt;So, the best fit had to check a few boxes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[x] no API key&lt;/li&gt;
&lt;li&gt;[x] no external server&lt;/li&gt;
&lt;li&gt;[x] no extra runtime I did not already want/install&lt;/li&gt;
&lt;li&gt;[x] storage isolated by &lt;code&gt;HERMES_HOME&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[x] memory we can actually read later&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That let to &lt;a href="https://github.com/MemPalace/mempalace" rel="noopener noreferrer"&gt;MemPalace&lt;/a&gt;, or &lt;a href="https://mempalaceofficial.com/" rel="noopener noreferrer"&gt;https://mempalaceofficial.com/&lt;/a&gt; (hopefully, that's the right one!)&lt;/p&gt;

&lt;h2&gt;
  
  
  What hermes-mempalace does
&lt;/h2&gt;

&lt;p&gt;hermes-mempalace wires MemPalace into the Hermes memory provider interface.&lt;/p&gt;

&lt;p&gt;It follows the same lifecycle as the rest of Hermes memory providers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;system_prompt_block()&lt;/code&gt; adds a short memory reminder to the prompt.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;prefetch()&lt;/code&gt; can run a MemPalace search before the first model call.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sync_turn()&lt;/code&gt; buffers completed turns without slowing the chat loop.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;on_session_end()&lt;/code&gt; writes buffered turns to markdown and mines them into the palace.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;shutdown()&lt;/code&gt; flushes anything still waiting.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;During a session, Hermes gets three tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;mempalace_search&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mempalace_wake_up&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mempalace_status&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That gives the agent a simple pattern: find relevant past context, surface it early, and keep the full record available if you need to inspect it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Storage is explicit
&lt;/h3&gt;

&lt;p&gt;The plugin stores data under the current Hermes profile, not in some shared global bucket.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$HERMES_HOME/mempalace/palace/          # palace index
$HERMES_HOME/mempalace/conversations/   # mined transcripts as markdown
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That was important to mw. Profile isolation should be structural, not something you hope the config handles correctly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install
&lt;/h3&gt;

&lt;p&gt;If you already use Hermes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="sb"&gt;`&lt;/span&gt;
hermes memory setup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install the MemPalace CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;uv tool &lt;span class="nb"&gt;install &lt;/span&gt;mempalace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then verify everything is in place:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hermes memory status
hermes plugins list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What it feels like in practice
&lt;/h3&gt;

&lt;p&gt;The main difference is not flashy.&lt;/p&gt;

&lt;p&gt;It is that &lt;code&gt;mempalace_wake_up&lt;/code&gt; gives Hermes useful context at the start of a session without turning the whole memory layer into a black box.&lt;/p&gt;

&lt;p&gt;You can inspect the transcripts. You can search them. You can open the directory and see what happened. If you want to prune or review something, you are not fighting the system.&lt;/p&gt;

&lt;p&gt;That is the part I cared about most.&lt;/p&gt;

&lt;p&gt;Hermes still keeps its built-in memory. hermes-mempalace does not replace that. It adds an archival layer on top of it. One that feels a lot more like a real notebook than a hidden model feature.&lt;/p&gt;

&lt;p&gt;If this sounds useful... let me know :)&lt;/p&gt;

&lt;p&gt;If you are already happy with Hermes memory, you probably do not need this.&lt;/p&gt;

&lt;p&gt;But if you want:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;local-first memory&lt;/li&gt;
&lt;li&gt;profile-scoped storage&lt;/li&gt;
&lt;li&gt;verbatim transcript mining&lt;/li&gt;
&lt;li&gt;a readable on-disk layout &lt;/li&gt;
&lt;li&gt;no extra server to babysit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;then hermes-mempalace may be a good fit.&lt;/p&gt;

&lt;p&gt;The plugin is MIT licensed, and the repo is here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/abdallah/hermes-mempalace" rel="noopener noreferrer"&gt;https://github.com/abdallah/hermes-mempalace&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>opensource</category>
      <category>devops</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Quick WHM/cPanel All email passwords reset </title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Fri, 07 May 2021 08:42:14 +0000</pubDate>
      <link>https://dev.to/abdallah/quick-whm-cpanel-all-email-passwords-reset-1cma</link>
      <guid>https://dev.to/abdallah/quick-whm-cpanel-all-email-passwords-reset-1cma</guid>
      <description>&lt;p&gt;You generally don’t want to use this script. This is a last resort, when all mailbox passwords for the entire account need to be changed. For this script to work, you need root access to your WHM/cPanel server. This could ruin everything, be warned!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here be dragons!&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nv"&gt;newpass&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'SomeStr0ngPasswordGoesHere!'&lt;/span&gt;
&lt;span class="nv"&gt;accountname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'example'&lt;/span&gt;
&lt;span class="nv"&gt;domainname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'example.com'&lt;/span&gt;

uapi &lt;span class="nt"&gt;--user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$accountname&lt;/span&gt; Email list_pops &lt;span class="se"&gt;\&lt;/span&gt;
  | &lt;span class="nb"&gt;grep &lt;/span&gt;email &lt;span class="se"&gt;\&lt;/span&gt;
  | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'{print$2}'&lt;/span&gt; | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="nt"&gt;-F&lt;/span&gt;&lt;span class="se"&gt;\@&lt;/span&gt; &lt;span class="s1"&gt;'{print$1}'&lt;/span&gt; | &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;read &lt;/span&gt;m&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;changing password &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nv"&gt;$m&lt;/span&gt;
    uapi &lt;span class="nt"&gt;--user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;@accountname Email passwd_pop &lt;span class="nv"&gt;domain&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$domainname&lt;/span&gt; &lt;span class="nv"&gt;email&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$m&lt;/span&gt; &lt;span class="nv"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$newpass&lt;/span&gt;
  &lt;span class="k"&gt;done
&lt;/span&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here are the links to the official API docs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Apasswd%5C_pop"&gt;https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Apasswd\_pop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Alist%5C_pops"&gt;https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Alist\_pops&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Is there a better way to do this?&lt;/strong&gt; probably&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I randomize the password?&lt;/strong&gt; sure, but how will you send the new passwords to your users?&lt;/p&gt;

&lt;p&gt;Hope it helps!&lt;/p&gt;

</description>
      <category>bash</category>
      <category>cpanel</category>
      <category>password</category>
      <category>script</category>
    </item>
    <item>
      <title>Quick ElasticSearch Index Cleanup</title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Wed, 07 Apr 2021 08:50:38 +0000</pubDate>
      <link>https://dev.to/abdallah/quick-elasticsearch-index-cleanup-4kjo</link>
      <guid>https://dev.to/abdallah/quick-elasticsearch-index-cleanup-4kjo</guid>
      <description>&lt;p&gt;There are many solutions using &lt;code&gt;curator&lt;/code&gt; and other libraries. I’ll try to add links here later (if I remember)&lt;/p&gt;

&lt;p&gt;However, most of the time, all that’s needed is a quick &lt;code&gt;curl&lt;/code&gt; call&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X DELETE "https://${ES-Endpoint}/${INDEX_NAME}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get the ES endpoint from the domain overview&lt;/p&gt;

&lt;p&gt;List the index names using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl "https://${ES-Endpoint}/_cat/indices"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So for a quick cleanup session for everything that matches a grep&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl "https://${ES-Endpoint}/_cat/indices" | grep 'something' | awk '{print$3}' \
while read INDEX_NAME; do
  echo "Deleting ${INDEX_NAME}"
  curl -X DELETE "https://${ES-Endpoint}/${INDEX_NAME}"
done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>blogging</category>
      <category>bash</category>
      <category>curl</category>
      <category>elasticsearch</category>
    </item>
    <item>
      <title>My Ansible AWS EC2 Dynamic Inventory</title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Tue, 11 Aug 2020 11:22:35 +0000</pubDate>
      <link>https://dev.to/abdallah/my-ansible-aws-ec2-dynamic-inventory-1fe3</link>
      <guid>https://dev.to/abdallah/my-ansible-aws-ec2-dynamic-inventory-1fe3</guid>
      <description>&lt;p&gt;Start with the the Ansible configuration. This can be set in &lt;code&gt;/etc/ansible/ansible.cfg&lt;/code&gt; or &lt;code&gt;~/.ansible.cfg&lt;/code&gt; (in the home directory) or &lt;code&gt;ansible.cfg&lt;/code&gt; (in the current directory)&lt;/p&gt;

&lt;p&gt;My suggestion is use one of the first 2 (ie. &lt;code&gt;/etc/&lt;/code&gt; or &lt;code&gt;~/.ansible.cfg&lt;/code&gt; if you’re going to be managing instances from your machine. Update the configuration as needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[defaults]&lt;/span&gt;
&lt;span class="py"&gt;inventory&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;./ansible_plugins&lt;/span&gt;
&lt;span class="py"&gt;enable_plugins&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;aws_ec2&lt;/span&gt;
&lt;span class="py"&gt;host_key_checking&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;False&lt;/span&gt;
&lt;span class="py"&gt;pipelining&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;True&lt;/span&gt;
&lt;span class="py"&gt;log_path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;/var/log/ansible&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You may need other plugins, this one is for aws_ec2. In the /etc/ansible/ansible_plugins directory, create the *_aws_ec2.yml configuration file for your inventory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# /etc/ansible/ansible_plugins/testing_aws_ec2.yml&lt;/span&gt;
&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="na"&gt;plugin&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;aws_ec2&lt;/span&gt;
&lt;span class="na"&gt;aws_profile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;testing&lt;/span&gt;
&lt;span class="na"&gt;regions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;us-east-1&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;us-east-2&lt;/span&gt;
&lt;span class="na"&gt;filters&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="s"&gt;tag:Team: testing&lt;/span&gt;
  &lt;span class="s"&gt;instance-state-name&lt;/span&gt; &lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;running&lt;/span&gt;
&lt;span class="na"&gt;hostnames&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;instance-id&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;dns-name&lt;/span&gt;
&lt;span class="na"&gt;keyed_groups&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;prefix&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;team&lt;/span&gt;
    &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tags['Team']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You'll notice, I’m filtering using a &lt;code&gt;tag:Team == testing&lt;/code&gt; and showing only &lt;code&gt;running&lt;/code&gt; instances.&lt;/p&gt;

&lt;p&gt;I’m also using the &lt;code&gt;instance-id&lt;/code&gt; and &lt;code&gt;dns-name&lt;/code&gt; attributes as hostname&lt;/p&gt;

&lt;p&gt;And I’m using the &lt;code&gt;tag['Team']&lt;/code&gt; as a grouping.&lt;/p&gt;

&lt;p&gt;So now, I can do the following from any directory (since my configuration is global in &lt;code&gt;/etc/ansible&lt;/code&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ansible-inventory --list --yaml
all:
  children:
    aws_ec2:
      hosts:
        i-xxxxxxxxxxxxxxx:
          ami_launch_index: 0
          architecture: x86_64
          block_device_mappings:
          - device_name: /dev/sda1
            ebs:
              attach_time: 2020-08-10 15:20:58+00:00
              delete_on_termination: true
              status: attached
              volume_id: vol-xxxxxxxxxxxxxx
...
    team_testing:
      hosts:
        i-xyxyxyxyxyyxyxyy: {}
        i-xyxyxy2321yxyxyy: {}
        i-xyxyxyxyxy89yxyy: {}
        i-xyxy1210xyyxyxyy: {}
        i-xyxy999999yxyxyy: {}
        i-xyxyxy44xyyxyxyy: {}
        i-xyx2323yxyyxyxyy: {}
        i-xyxyxyxyxy9977yy: {}
    ungrouped: {}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I can also use the &lt;code&gt;team_testing&lt;/code&gt; or the individual &lt;code&gt;instance_id&lt;/code&gt; in my Ansible &lt;code&gt;hosts&lt;/code&gt; calls.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
    </item>
    <item>
      <title>Get daily cost alerts for AWS</title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Tue, 23 Jun 2020 05:53:04 +0000</pubDate>
      <link>https://dev.to/abdallah/get-daily-cost-alerts-for-aws-5bm</link>
      <guid>https://dev.to/abdallah/get-daily-cost-alerts-for-aws-5bm</guid>
      <description>&lt;p&gt;So I wanted to have a better alarm system for when AWS hits us with unexpected costs. It’s better to know there’s something wrong rather quickly and not suffer hundreds of dollars costs for something you don’t really need or want.&lt;/p&gt;

&lt;p&gt;The AWS provided alarm checks for hikes on a monthly basis. Here’s the &lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html"&gt;doc they published&lt;/a&gt;. So that’s an alarm that sounds when your estimated bill is going to be higher than the budgeted amount, or what you had in mind in the first place. Not very useful honestly in our case. It will just be too late.&lt;/p&gt;

&lt;p&gt;The only alternative I found was creating a daily check, that will compare yesterday’s costs against a max_amount set by default. Let’s say you want to have your daily bill not exceed 5$US.&lt;/p&gt;

&lt;p&gt;For ease of use and maintainability, I’m using a lambda function triggered by a cron (EventBridge rule) for the daily checks. And I’m sending the Alarm using an SNS topic, this way I can subscribe to it by email, or send it to our Mattermost channel, etc.&lt;/p&gt;

&lt;p&gt;Here’s the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;boto3&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lambda_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;yesterday&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s"&gt;'%Y-%m-%d'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;twodaysago&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s"&gt;'%Y-%m-%d'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cost_metric&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'cost_metric'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;max_amount&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'max_amount'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;ce&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'ce'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;sns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'sns'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ce&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_cost_and_usage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;TimePeriod&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'Start'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;twodaysago&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'End'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;yesterday&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; 
        &lt;span class="n"&gt;Granularity&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'DAILY'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="n"&gt;Metrics&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cost_metric&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;total_amount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'ResultsByTime'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Total'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cost_metric&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Amount'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;total_amount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;max_amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;sns_topic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_topic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'BillingAlert'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;sns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;TopicArn&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sns_topic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'TopicArn'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;   
            &lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'Total cost "{} USD" exceeded max_amount rate: {}'&lt;/span&gt;
                     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total_amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   
        &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;'statusCode'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;'body'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'cost check: {}'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total_amount&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note that you will need to add a couple of environment variables to Lambda: &lt;code&gt;cost_metric&lt;/code&gt; and &lt;code&gt;max_amount&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And add the following permissions to the role used by the lambda function: &lt;code&gt;ce:GetCostAndUsage&lt;/code&gt;, &lt;code&gt;sns:Publish&lt;/code&gt; and &lt;code&gt;sns:CreateTopic&lt;/code&gt;. Something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"VisualEditor0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ce:GetCostAndUsage"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"VisualEditor1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"logs:CreateLogStream"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"sns:Publish"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"sns:CreateTopic"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"logs:PutLogEvents"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:logs:us-east-1:*:log-group:/aws/lambda/checkDailyCosts:*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:sns:*:*:*"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"VisualEditor2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"logs:CreateLogGroup"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:logs:us-east-1:*:*"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After that’s setup, go to your SNS topic (created by Lambda if it doesn’t exist) and subscribe to it. There you go, daily checks and an alarm if the bill is higher than expected.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cost</category>
      <category>lambda</category>
      <category>python</category>
    </item>
    <item>
      <title>Get daily cost alerts on AWS</title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Thu, 18 Jun 2020 15:42:00 +0000</pubDate>
      <link>https://dev.to/abdallah/get-daily-cost-alerts-on-aws-51mb</link>
      <guid>https://dev.to/abdallah/get-daily-cost-alerts-on-aws-51mb</guid>
      <description>&lt;p&gt;So I wanted to have a better alarm system for when AWS hits us with unexpected costs. It’s better to know there’s something wrong rather quickly and not suffer hundreds of dollars costs for something you don’t really need or want.&lt;/p&gt;

&lt;p&gt;The AWS provided alarm checks for hikes on a monthly basis. Here’s the &lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/monitor_estimated_charges_with_cloudwatch.html"&gt;doc they published&lt;/a&gt;. So that’s an alarm that sounds when your estimated bill is going to be higher than the budgeted amount, or what you had in mind in the first place. Not very useful honestly in our case. It will just be too late.&lt;/p&gt;

&lt;p&gt;The only alternative I found was creating a daily check, that will compare yesterday’s costs against a max_amount set by default. Let’s say you want to have your daily bill not exceed 5$US.&lt;/p&gt;

&lt;p&gt;For ease of use and maintainability, I’m using a lambda function triggered by a cron (EventBridge rule) for the daily checks. And I’m sending the Alarm using an SNS topic, this way I can subscribe to it by email, or send it to our Mattermost channel, etc.&lt;/p&gt;

&lt;p&gt;Here’s the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;boto3&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lambda_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;yesterday&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s"&gt;'%Y-%m-%d'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;twodaysago&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s"&gt;'%Y-%m-%d'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cost_metric&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'cost_metric'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;max_amount&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'max_amount'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;ce&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'ce'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;sns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'sns'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ce&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get_cost_and_usage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;TimePeriod&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'Start'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;twodaysago&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'End'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;yesterday&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; 
        &lt;span class="n"&gt;Granularity&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'DAILY'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="n"&gt;Metrics&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cost_metric&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;total_amount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'ResultsByTime'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Total'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cost_metric&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Amount'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;total_amount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;max_amount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;sns_topic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_topic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'BillingAlert'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;sns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;TopicArn&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sns_topic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'TopicArn'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;   
            &lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'Total cost "{} USD" exceeded max_amount rate: {}'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total_amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   
        &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;'statusCode'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;'body'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'cost check: {}'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total_amount&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that you will need to add a couple of environment variables to Lambda: &lt;code&gt;cost_metric&lt;/code&gt; and &lt;code&gt;max_amount&lt;/code&gt;&lt;br&gt;&lt;br&gt;
And the following permissions to the role used by the lambda function: &lt;code&gt;ce:GetCostAndUsage&lt;/code&gt;, &lt;code&gt;sns:Publish&lt;/code&gt; and &lt;code&gt;sns:CreateTopic&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "ce:GetCostAndUsage",
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "sns:Publish",
                "sns:CreateTopic",
                "logs:PutLogEvents"
            ],
            "Resource": [
                "arn:aws:logs:us-east-1:*:log-group:/aws/lambda/checkDailyCosts:*",
                "arn:aws:sns:*:*:*"
            ]
        },
        {
            "Sid": "VisualEditor2",
            "Effect": "Allow",
            "Action": "logs:CreateLogGroup",
            "Resource": "arn:aws:logs:us-east-1:*:*"
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that’s set up, go to your SNS topic (created by Lambda if it doesn’t exist) and subscribe to it. There you go, daily checks and an alarm if the bill is higher than expected.&lt;/p&gt;

</description>
      <category>tools</category>
      <category>work</category>
      <category>aws</category>
      <category>costsavings</category>
    </item>
    <item>
      <title>Sync S3 objects across AWS account?</title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Tue, 12 May 2020 09:42:00 +0000</pubDate>
      <link>https://dev.to/abdallah/sync-s3-objects-across-aws-account-54i9</link>
      <guid>https://dev.to/abdallah/sync-s3-objects-across-aws-account-54i9</guid>
      <description>&lt;p&gt;How do I copy S3 objects/files/etc from another AWS account?&lt;br&gt;
How do I migrate an S3 bucket to another AWS account? [playbook below + extra preliminary step, create the bucket]&lt;/p&gt;

&lt;p&gt;Well, you can do it manually following the notes in the AWS KB article I linked at the end of the article. &lt;br&gt;
Honestly though, I am always confused by those KB articles. They are concise ans usually well written. I guess it's my dislexya ;)&lt;br&gt;
So I have to read them a few times before I’m able to apply the steps correctly. That's not a bad thing really ... better than blindly copy/paste commands (which I NEVER DO, right).&lt;/p&gt;

&lt;p&gt;Recently, I’ve been going the other way around: whenever there are steps to follow, I try to translate them into an Ansible playbook. This way I make sure I got it right, AND I get to reuse the playbook, which makes things a lot faster the second time around. Oh and as an added bonus, I can share the playbook and have someone else take care of the task!&lt;/p&gt;

&lt;p&gt;Enough introductions, here’s what you came here for: an ansible playbook for syncing files between S3 buckets in different accounts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# copy-bucket.yml&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;hosts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;localhost&lt;/span&gt;
  &lt;span class="na"&gt;vars&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;source_bucket&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-source-bucket&lt;/span&gt;  
    &lt;span class="na"&gt;dest_bucket&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-dest-bucket&lt;/span&gt;
    &lt;span class="na"&gt;dest_user_arn&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;arn:aws:iam::ACCOUNTID:user/USERNAME&lt;/span&gt;
    &lt;span class="na"&gt;dest_user_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;USERNAME&lt;/span&gt;
    &lt;span class="na"&gt;source_profile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;src_profile&lt;/span&gt;
    &lt;span class="na"&gt;dest_profile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dest_profile&lt;/span&gt;
  &lt;span class="na"&gt;tasks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Attach bucket policy to source bucket&lt;/span&gt;
      &lt;span class="na"&gt;s3_bucket&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;source_bucket&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}"&lt;/span&gt;
        &lt;span class="na"&gt;policy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;lookup('template','bucket-policy.json.j2')&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}"&lt;/span&gt;
        &lt;span class="na"&gt;profile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;source_profile&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}"&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Attach an IAM policy to a user in dest account&lt;/span&gt;
      &lt;span class="na"&gt;iam_policy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;iam_type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;user&lt;/span&gt;
        &lt;span class="na"&gt;iam_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;dest_user_name&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}"&lt;/span&gt;
        &lt;span class="na"&gt;policy_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;s3_move_access"&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;present&lt;/span&gt;
        &lt;span class="na"&gt;policy_json&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;lookup(&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;'template',&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;'user-policy.json.j2')&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}"&lt;/span&gt;
        &lt;span class="na"&gt;profile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;dest_profile&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}"&lt;/span&gt;
      &lt;span class="na"&gt;register&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;user_policy&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Sync the files&lt;/span&gt; 
      &lt;span class="na"&gt;shell&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;aws s3 sync s3://{{ source_bucket }}/ s3://{{ dest_bucket }}/ --profile {{ dest_profile }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You will also need the following json templates&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;bucket-policy.json.j2&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:ListBucket"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:GetObject"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::{{ source_bucket }}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::{{ source_bucket }}/*"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:ListBucket"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:PutObject"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"s3:PutObjectAcl"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::{{ dest_bucket }}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::{{ dest_bucket }}/*"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;user-policy.json.j2&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"DelegateS3Access"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Principal"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"AWS"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"{{ dest_user_arn }}"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"s3:ListBucket"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"s3:GetObject"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::{{ source_bucket }}/*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:s3:::{{ source_bucket }}"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;run: &lt;code&gt;ansible-playbook -v copy-bucket.yml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;make sure the profile names are setup on your machine correctly, and the IAM user is there.&lt;/p&gt;

&lt;p&gt;Ref: &lt;a href="https://aws.amazon.com/premiumsupport/knowledge-center/copy-s3-objects-account/"&gt;AWS KB: copy-s3-objects-account&lt;/a&gt;&lt;/p&gt;

</description>
      <category>s3</category>
      <category>ansible</category>
      <category>aws</category>
      <category>devops</category>
    </item>
    <item>
      <title>ChatOps with Mattermost and AWS Lambda</title>
      <dc:creator>Abdallah Deeb</dc:creator>
      <pubDate>Fri, 14 Jun 2019 18:09:07 +0000</pubDate>
      <link>https://dev.to/abdallah/chatops-with-mattermost-and-aws-lambda-2ha0</link>
      <guid>https://dev.to/abdallah/chatops-with-mattermost-and-aws-lambda-2ha0</guid>
      <description>&lt;p&gt;I’ve been working towards making things simpler when managing distributed resources at work. And since we spend most of our day in the chat room (was Slack, now Mattermost) I thought it’s best to get started with ChatOps&lt;/p&gt;

&lt;p&gt;It’s just a fancy word for doing stuff right from the chat window. And there’s so much one can do, especially with simple Slash Commands.&lt;/p&gt;

&lt;p&gt;Here’s a lambda function I setup yesterday for invalidating CloudFront distributions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;time&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;boto3&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;re&lt;/span&gt;


&lt;span class="n"&gt;EXPECTED_TOKEN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'mmToken'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;ALLOWED_USERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'[, ]'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'allowedUsers'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;DISTRIBUTIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;'site-name'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'DISTRIBUTIONID'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;'another.site'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'DISTRIBUTIONID05'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;parse_command_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command_text&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="s"&gt;"({})\s+(.*)"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'|'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DISTRIBUTIONS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
    &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;command_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;'site'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s"&gt;'path'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lambda_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Parse the request
&lt;/span&gt;    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;request_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"queryStringParameters"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"statusCode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s"&gt;"headers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="s"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'{ "message": "Use GET for setting up mattermost slash command" }'&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;# Check the token matches.
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;request_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"token"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;EXPECTED_TOKEN&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Wrong Token!'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"statusCode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s"&gt;"headers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="s"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'{ "message": "Mattermost token does not match" }'&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;# Check the user is allowed to run the command
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;request_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"user_name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;ALLOWED_USERS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Wrong User! {} not in {}'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request_data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'user_name'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;ALLOWED_USERS&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"statusCode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s"&gt;"headers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="s"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'{ "message": "User not allowed to perform action" }'&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;# parse the command
&lt;/span&gt;    &lt;span class="n"&gt;command_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;command_text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Nothing to do, bailing out'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"statusCode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s"&gt;"headers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="s"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'{ "message": "No command text sent" }'&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;parts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parse_command_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Bad formatting - command: {}'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command_text&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;"statusCode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;402&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s"&gt;"headers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="s"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'{ "message": "Wrong pattern" }'&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;


    &lt;span class="c1"&gt;# Do the actual work
&lt;/span&gt;    &lt;span class="n"&gt;cf_client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'cloudfront'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Invalidate
&lt;/span&gt;    &lt;span class="n"&gt;boto_response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cf_client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_invalidation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;DistributionId&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;DISTRIBUTIONS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'site'&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;
        &lt;span class="n"&gt;InvalidationBatch&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;'Paths'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="s"&gt;'Quantity'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'path'&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
                &lt;span class="s"&gt;'Items'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'path'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; 
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="s"&gt;'CallerReference'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="n"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="s"&gt;'Invalidation'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="c1"&gt;# Build the response message text.
&lt;/span&gt;    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"""##### Executing invalidation
| Key | Info |
| --- | ---- |
| Site | {} |
| Path | {} |
| ID | {} |
| Status | {} |"""&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'site'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; 
        &lt;span class="n"&gt;parts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'path'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="n"&gt;boto_response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Id'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; 
        &lt;span class="n"&gt;boto_response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Status'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Build the response object.
&lt;/span&gt;    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;"response_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"in_channel"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;# Return the response as JSON
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="s"&gt;"headers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;"Content-Type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"application/json"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="s"&gt;"statusCode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that you need to hook that up with an API Gateway in AWS. Once that’s done, you will have a URL endpoint ready for deployment.&lt;/p&gt;

&lt;p&gt;Next, I created the slash command in mattermost with the following:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KIW8MPus--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://deeb.me/wp-content/uploads/image-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KIW8MPus--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://deeb.me/wp-content/uploads/image-1.png" alt=""&gt;&lt;/a&gt;slash command configuration&lt;p&gt;&lt;/p&gt;

&lt;p&gt;That’s pretty much it. Rinse and repeat for a different command, different usage.&lt;/p&gt;

&lt;p&gt;On my list next is to have more interaction with the user in mattermost per &lt;a href="https://docs.mattermost.com/developer/interactive-messages.html"&gt;https://docs.mattermost.com/developer/interactive-messages.html&lt;/a&gt;&lt;br&gt;&lt;br&gt;
Weekend Project, Yay!&lt;/p&gt;

</description>
      <category>blogging</category>
      <category>tools</category>
      <category>work</category>
      <category>aws</category>
    </item>
  </channel>
</rss>
