Um blog sobre nada

Um conjunto de inutilidades que podem vir a ser úteis

Archive for the ‘DevOps’ Category

Changing windows password without CTR + ALT + DEL

Posted by Diego on April 29, 2020

We’ve all been there: trying to change your passwrod while on a RDP sessions. CTRL + ALT + DEL doesn’t work. The virtual keyboard doesnt work, the “accounts” settings tell you to issue a CTRL + ALT + DEL….. so PowerShell to the rescue:

$AccountName = '<Your Account>'
 
$current = Read-Host -asSecureString "Enter the current password"
$newpw = Read-Host -asSecureString "Enter the new password"
 
Set-AdAccountPassword -Identity $AccountName -OldPassword $current -NewPassword $newpw

Posted in DevOps | Leave a Comment »

Docker + Windows – error: "exited with code 127"

Posted by Diego on March 25, 2020

Problem: on Windos, when cloning a repo from git that has bash files, you may get the above error in one of the bash files.

Explanation: It turns out that windows and git have a problem with “end of line” characters as a cloned repository will contain crlf line breaks, instead of lf (more info here).

Solution: clone your repo with the “–config core.autocrlf=input” option.

Posted in DevOps | Leave a Comment »

AWS CodePipeline – SNS Notifications using existing Topics

Posted by Diego on November 20, 2019

AWS recently release the functionaly of setting up notification for CodePipeline using SNS.

“You can now receive notifications about events in repositories, build projects, deployments, and pipelines when you use AWS CodeCommitAWS CodeBuildAWS CodeDeploy, and/or AWS CodePipeline. Notifications will come in the form of Amazon SNS notifications. Each notification will include a status message as well as a link to the resources whose event generated that notification.”

When I tested the functionalty the first time, I created the SNS topic using the console (during the Notification Rule creation) and everything worked as expected.

After the test, I decided to create the resources (specially the SNS topic) using cloud formation and I noticed that the notification weren’t being published to the topic anymore.

After some research I found this on the AWS documentation:

“If you want to use an existing Amazon SNS topic instead of creating a new one, in Targets, choose its ARN. Make sure the topic has the appropriate access policy,….”

And indeed I realised that, when the topic was  being created by the console, it added permission to “codestar” to publish to the topic…something that I never imagined necessary, because I didn’t know codestar was part of the equation.

In CloudFormation words, what I needed to do was something liem this:

FYI: the __default_statement_ID Sid is created automatically by cloudformation if you don’t specify a “TopicPolicy”. Since we are adding the “codestar” permission, we need to add the default statement (if, of course you actually need those permissions)

PipelineNotificationTopic:
    Type: AWS::SNS::Topic
    Properties: 
      DisplayName: MyTopicDisplayName
      TopicName: MyTopicName
  
  PipelineNotificationTopicPolicy:
    Type: AWS::SNS::TopicPolicy
    Properties: 
      PolicyDocument: 
        Version: '2008-10-17'
        Statement:
        - Sid: CodeNotification_publish
          Effect: Allow
          Principal:
            Service: codestar-notifications.amazonaws.com
          Action: SNS:Publish
          Resource: !Ref PipelineNotificationTopic

        - Sid: __default_statement_ID
          Effect: Allow
          Principal:
            AWS: "*"
          Action:
          - SNS:GetTopicAttributes
          - SNS:SetTopicAttributes
          - SNS:AddPermission
          - SNS:RemovePermission
          - SNS:DeleteTopic
          - SNS:Subscribe
          - SNS:ListSubscriptionsByTopic
          - SNS:Publish
          - SNS:Receive
          Resource: !Ref PipelineNotificationTopic
          Condition:
            StringEquals:
              AWS:SourceOwner: !Sub ${AWS::AccountId}

      Topics: 
        - !Ref PipelineNotificationTopic

Posted in AWS, CodePipeline, DevOps, SNS | 2 Comments »

AWS CodePipeline – Using SAM to create a Sample Template

Posted by Diego on November 11, 2019

This is very useful if you don’t want to write a template from scratch



  1. Install the AWS Serverless Application Model (SAM);
  2. Create the cloud formation template:
    1. Navigate to an empty folder
    2. run: sam init –location gh:aws-samples/cookiecutter-aws-sam-pipeline
    3. Follow the instructions
    4. (the error message is expected – I always get it but it works fine)
    5. adapt the files sample_buildspec.yaml and sample_pipeline.yaml as you like
  3. Run the pipeline.yaml to create the pipeline;
  4. As a further suggestion, place the buildspec.yaml and pipeline.yaml files at the root of your code commit repository to keep track on their changes;



Posted in AWS, CodePipeline, DevOps | Leave a Comment »