HashiCorp Packer AWS Tutorial: AMI Example | Builder | Provisioner | EC2 |Tags |SSH |Debug

HashiCorp Packer AWS Tutorial will teach you how to create AMI images in AWS using the packer automation tool. You will get a packer AMI Example that you can follow to build your own packer AMI images from scratch. HashiCorp Packer is an amazing tool to build an immutable infrastructure that simplifies the deployment process.

Did I help you out?
☕ Buy Me a Coffe: https://www.buymeacoffee.com/antonputra
🔴 Add me on LinkedIn: https://www.linkedin.com/in/anton-putra

=========
⏱️TIMESTAMPS⏱️
0:00 Intro
0:28 Create Packer Template
1:37 Run packer build
1:56 Update Packer Template to Install Nginx
2:50 Build Final Packer Image
4:13 SSH to Packer EC2 to debug

=========
Source Code
🖥️ - GitHub: https://github.com/antonputra/tutorials/tree/main/lessons/062

=========
SOCIAL
🎙 - Twitter: https://twitter.com/antonvputra
📨 - Email: me@antonputra.com

#Packer #HashiCorp #AWS

#aws #hashicorp #packer

What is GEEK

Buddha Community

HashiCorp Packer AWS Tutorial: AMI Example | Builder | Provisioner | EC2 |Tags |SSH |Debug
Lawrence  Lesch

Lawrence Lesch

1677668905

TS-mockito: Mocking Library for TypeScript

TS-mockito

Mocking library for TypeScript inspired by http://mockito.org/

1.x to 2.x migration guide

1.x to 2.x migration guide

Main features

  • Strongly typed
  • IDE autocomplete
  • Mock creation (mock) (also abstract classes) #example
  • Spying on real objects (spy) #example
  • Changing mock behavior (when) via:
  • Checking if methods were called with given arguments (verify)
    • anything, notNull, anyString, anyOfClass etc. - for more flexible comparision
    • once, twice, times, atLeast etc. - allows call count verification #example
    • calledBefore, calledAfter - allows call order verification #example
  • Resetting mock (reset, resetCalls) #example, #example
  • Capturing arguments passed to method (capture) #example
  • Recording multiple behaviors #example
  • Readable error messages (ex. 'Expected "convertNumberToString(strictEqual(3))" to be called 2 time(s). But has been called 1 time(s).')

Installation

npm install ts-mockito --save-dev

Usage

Basics

// Creating mock
let mockedFoo:Foo = mock(Foo);

// Getting instance from mock
let foo:Foo = instance(mockedFoo);

// Using instance in source code
foo.getBar(3);
foo.getBar(5);

// Explicit, readable verification
verify(mockedFoo.getBar(3)).called();
verify(mockedFoo.getBar(anything())).called();

Stubbing method calls

// Creating mock
let mockedFoo:Foo = mock(Foo);

// stub method before execution
when(mockedFoo.getBar(3)).thenReturn('three');

// Getting instance
let foo:Foo = instance(mockedFoo);

// prints three
console.log(foo.getBar(3));

// prints null, because "getBar(999)" was not stubbed
console.log(foo.getBar(999));

Stubbing getter value

// Creating mock
let mockedFoo:Foo = mock(Foo);

// stub getter before execution
when(mockedFoo.sampleGetter).thenReturn('three');

// Getting instance
let foo:Foo = instance(mockedFoo);

// prints three
console.log(foo.sampleGetter);

Stubbing property values that have no getters

Syntax is the same as with getter values.

Please note, that stubbing properties that don't have getters only works if Proxy object is available (ES6).

Call count verification

// Creating mock
let mockedFoo:Foo = mock(Foo);

// Getting instance
let foo:Foo = instance(mockedFoo);

// Some calls
foo.getBar(1);
foo.getBar(2);
foo.getBar(2);
foo.getBar(3);

// Call count verification
verify(mockedFoo.getBar(1)).once();               // was called with arg === 1 only once
verify(mockedFoo.getBar(2)).twice();              // was called with arg === 2 exactly two times
verify(mockedFoo.getBar(between(2, 3))).thrice(); // was called with arg between 2-3 exactly three times
verify(mockedFoo.getBar(anyNumber()).times(4);    // was called with any number arg exactly four times
verify(mockedFoo.getBar(2)).atLeast(2);           // was called with arg === 2 min two times
verify(mockedFoo.getBar(anything())).atMost(4);   // was called with any argument max four times
verify(mockedFoo.getBar(4)).never();              // was never called with arg === 4

Call order verification

// Creating mock
let mockedFoo:Foo = mock(Foo);
let mockedBar:Bar = mock(Bar);

// Getting instance
let foo:Foo = instance(mockedFoo);
let bar:Bar = instance(mockedBar);

// Some calls
foo.getBar(1);
bar.getFoo(2);

// Call order verification
verify(mockedFoo.getBar(1)).calledBefore(mockedBar.getFoo(2));    // foo.getBar(1) has been called before bar.getFoo(2)
verify(mockedBar.getFoo(2)).calledAfter(mockedFoo.getBar(1));    // bar.getFoo(2) has been called before foo.getBar(1)
verify(mockedFoo.getBar(1)).calledBefore(mockedBar.getFoo(999999));    // throws error (mockedBar.getFoo(999999) has never been called)

Throwing errors

let mockedFoo:Foo = mock(Foo);

when(mockedFoo.getBar(10)).thenThrow(new Error('fatal error'));

let foo:Foo = instance(mockedFoo);
try {
    foo.getBar(10);
} catch (error:Error) {
    console.log(error.message); // 'fatal error'
}

Custom function

You can also stub method with your own implementation

let mockedFoo:Foo = mock(Foo);
let foo:Foo = instance(mockedFoo);

when(mockedFoo.sumTwoNumbers(anyNumber(), anyNumber())).thenCall((arg1:number, arg2:number) => {
    return arg1 * arg2; 
});

// prints '50' because we've changed sum method implementation to multiply!
console.log(foo.sumTwoNumbers(5, 10));

Resolving / rejecting promises

You can also stub method to resolve / reject promise

let mockedFoo:Foo = mock(Foo);

when(mockedFoo.fetchData("a")).thenResolve({id: "a", value: "Hello world"});
when(mockedFoo.fetchData("b")).thenReject(new Error("b does not exist"));

Resetting mock calls

You can reset just mock call counter

// Creating mock
let mockedFoo:Foo = mock(Foo);

// Getting instance
let foo:Foo = instance(mockedFoo);

// Some calls
foo.getBar(1);
foo.getBar(1);
verify(mockedFoo.getBar(1)).twice();      // getBar with arg "1" has been called twice

// Reset mock
resetCalls(mockedFoo);

// Call count verification
verify(mockedFoo.getBar(1)).never();      // has never been called after reset

You can also reset calls of multiple mocks at once resetCalls(firstMock, secondMock, thirdMock)

Resetting mock

Or reset mock call counter with all stubs

// Creating mock
let mockedFoo:Foo = mock(Foo);
when(mockedFoo.getBar(1)).thenReturn("one").

// Getting instance
let foo:Foo = instance(mockedFoo);

// Some calls
console.log(foo.getBar(1));               // "one" - as defined in stub
console.log(foo.getBar(1));               // "one" - as defined in stub
verify(mockedFoo.getBar(1)).twice();      // getBar with arg "1" has been called twice

// Reset mock
reset(mockedFoo);

// Call count verification
verify(mockedFoo.getBar(1)).never();      // has never been called after reset
console.log(foo.getBar(1));               // null - previously added stub has been removed

You can also reset multiple mocks at once reset(firstMock, secondMock, thirdMock)

Capturing method arguments

let mockedFoo:Foo = mock(Foo);
let foo:Foo = instance(mockedFoo);

// Call method
foo.sumTwoNumbers(1, 2);

// Check first arg captor values
const [firstArg, secondArg] = capture(mockedFoo.sumTwoNumbers).last();
console.log(firstArg);    // prints 1
console.log(secondArg);    // prints 2

You can also get other calls using first(), second(), byCallIndex(3) and more...

Recording multiple behaviors

You can set multiple returning values for same matching values

const mockedFoo:Foo = mock(Foo);

when(mockedFoo.getBar(anyNumber())).thenReturn('one').thenReturn('two').thenReturn('three');

const foo:Foo = instance(mockedFoo);

console.log(foo.getBar(1));    // one
console.log(foo.getBar(1));    // two
console.log(foo.getBar(1));    // three
console.log(foo.getBar(1));    // three - last defined behavior will be repeated infinitely

Another example with specific values

let mockedFoo:Foo = mock(Foo);

when(mockedFoo.getBar(1)).thenReturn('one').thenReturn('another one');
when(mockedFoo.getBar(2)).thenReturn('two');

let foo:Foo = instance(mockedFoo);

console.log(foo.getBar(1));    // one
console.log(foo.getBar(2));    // two
console.log(foo.getBar(1));    // another one
console.log(foo.getBar(1));    // another one - this is last defined behavior for arg '1' so it will be repeated
console.log(foo.getBar(2));    // two
console.log(foo.getBar(2));    // two - this is last defined behavior for arg '2' so it will be repeated

Short notation:

const mockedFoo:Foo = mock(Foo);

// You can specify return values as multiple thenReturn args
when(mockedFoo.getBar(anyNumber())).thenReturn('one', 'two', 'three');

const foo:Foo = instance(mockedFoo);

console.log(foo.getBar(1));    // one
console.log(foo.getBar(1));    // two
console.log(foo.getBar(1));    // three
console.log(foo.getBar(1));    // three - last defined behavior will be repeated infinity

Possible errors:

const mockedFoo:Foo = mock(Foo);

// When multiple matchers, matches same result:
when(mockedFoo.getBar(anyNumber())).thenReturn('one');
when(mockedFoo.getBar(3)).thenReturn('one');

const foo:Foo = instance(mockedFoo);
foo.getBar(3); // MultipleMatchersMatchSameStubError will be thrown, two matchers match same method call

Mocking interfaces

You can mock interfaces too, just instead of passing type to mock function, set mock function generic type Mocking interfaces requires Proxy implementation

let mockedFoo:Foo = mock<FooInterface>(); // instead of mock(FooInterface)
const foo: SampleGeneric<FooInterface> = instance(mockedFoo);

Mocking types

You can mock abstract classes

const mockedFoo: SampleAbstractClass = mock(SampleAbstractClass);
const foo: SampleAbstractClass = instance(mockedFoo);

You can also mock generic classes, but note that generic type is just needed by mock type definition

const mockedFoo: SampleGeneric<SampleInterface> = mock(SampleGeneric);
const foo: SampleGeneric<SampleInterface> = instance(mockedFoo);

Spying on real objects

You can partially mock an existing instance:

const foo: Foo = new Foo();
const spiedFoo = spy(foo);

when(spiedFoo.getBar(3)).thenReturn('one');

console.log(foo.getBar(3)); // 'one'
console.log(foo.getBaz()); // call to a real method

You can spy on plain objects too:

const foo = { bar: () => 42 };
const spiedFoo = spy(foo);

foo.bar();

console.log(capture(spiedFoo.bar).last()); // [42] 

Thanks


Download Details:

Author: NagRock
Source Code: https://github.com/NagRock/ts-mockito 
License: MIT license

#typescript #testing #mock 

HashiCorp Packer AWS Tutorial: AMI Example | Builder | Provisioner | EC2 |Tags |SSH |Debug

HashiCorp Packer AWS Tutorial will teach you how to create AMI images in AWS using the packer automation tool. You will get a packer AMI Example that you can follow to build your own packer AMI images from scratch. HashiCorp Packer is an amazing tool to build an immutable infrastructure that simplifies the deployment process.

Did I help you out?
☕ Buy Me a Coffe: https://www.buymeacoffee.com/antonputra
🔴 Add me on LinkedIn: https://www.linkedin.com/in/anton-putra

=========
⏱️TIMESTAMPS⏱️
0:00 Intro
0:28 Create Packer Template
1:37 Run packer build
1:56 Update Packer Template to Install Nginx
2:50 Build Final Packer Image
4:13 SSH to Packer EC2 to debug

=========
Source Code
🖥️ - GitHub: https://github.com/antonputra/tutorials/tree/main/lessons/062

=========
SOCIAL
🎙 - Twitter: https://twitter.com/antonvputra
📨 - Email: me@antonputra.com

#Packer #HashiCorp #AWS

#aws #hashicorp #packer

smm captain

1650364405

Best Instagram Hashtags for Reels, Giveaways, Travel, Fashion

Pick the right hash tags and enjoy likes and comments on the post.

Making engaging reels about the travels, fashion, fitness, contest, and more, the results are not satisfactory. All you get is a few likes, comments and nothing else. You need the engagement on your post to bring more business to you. How can you bring interaction to the content? Indeed you can buy real instagram likes uk to get high rates. But how can you make the Instagram world hit the likes button under the post? You need to boost the reach. You must present your content to the right audiences to get higher interaction rates. 

Your Instagram #tags are the power tool that works like magic for influencers and businesses. The blue text with # is the magical option that increases the viability of the posts. The Instagram algorithm keeps on changing, and now the engagement on the post is a must to place the content at a higher place in followers’ feed. For this, you require more likes and comments under the post. For this, you must lift the reach by using perfect tags.

Why are hashtags popular on Instagram?

Let me clear it for you. Do you know how many active users this digital handle has? It is about 2B and more, and the count is changing every day. Each of the followers must be posting something on the handles. Thousands of profit must be of a similar niche as yours. If you are the business and running the clothing brands, then many other companies deal with clothes. So, customers or followers have many choices to choose from. Why would they follow you or purchase from your companies?

Your reply must be that you offer quality material at the best rates. But how does anyone finds out about you? Indeed you can buy active instagram followers uk to bring more fans, but how can you boost the reach of your voices. All businesses must represent their product to the right audiences, but how?

Of course, hashtags.

Table of Contents

Not all Hashtags are for you

There are some basic tags that you can use, but if you are more specific about your approach, choose the relevant tags for your business. Your #tags game must be industry oriented. So in this part, you will learn about the famous tags as per various niches. 

Tags for Travel Niche

Indeed this niche is famous on Instagram, and influencers earn handsome amounts. These #tags are best for you if you possess a similar place. Use them smartly and rightly!

#TravelPhotography

#PicOfTheDay

#NaturePhotography

#TravelBlogger

#beautiful

#landscape

#adventure

#explore

#instatravel

#photo

#trip

#summer

#travelgram

#photography

#art

#travel

#wanderlust

#nature

#instagood

#PhotoOfTheDay

Tags for Fashion Industry

After thee travel next most famous niche is fashion. You can earn handsome amount form it. But for this you need to pick the right tags form the following:

  1. #bhfyp
  2. #smile
  3. #OutfitOfTheDay
  4. #FashionPhotography
  5. #FollowBack
  6. #ootd
  7. #FashionBlogger
  8. #WhatIWore
  9. #follow
  10. #fashionista
  11. #PhotoOfTheDay
  12. #StyleInspo
  13. #instastyle
  14. #love
  15. #CurrentlyWearing
  16. #FashionBlog
  17. #ShoppingAddict
  18. #LookGoodFeelGood
  19. #FashionAddict
  20. #FashionStyle
  21. #BeautyDoesntHaveToBePain
  22. #style
  23. #fashion
  24. #FollowForFollowBack
  25. #fashionable
  26. #l
  27. #PicOfTheDay
  28. #fashiongram

Tags for fitness Influencers

So, what to boost your fitness business then uses these tags and enjoys likes:

  1. #exercise
  2. #bodybuilding
  3. #life
  4. #gymlife
  5. #motivation
  6. #healthy
  7. #lifestyle
  8. #health
  9. #gym
  10. #sport
  11. #training
  12. #workout
  13. #HealthyLifestyle
  14. #muscle
  15. #fit
  16. #CrossFit
  17. #fitness
  18. #FitFam
  19. #goals
  20. #PersonalTrainer
  21. #FitnessMotivation

Best Tags for Giveaway

So, are you arranging the giveaway and want a maximum number of people to participate? If so, then it is time to boost the reach vis using these tags

  1. #giveaway
  2. #sweepstakes
  3. #WinItWednesday
  4. #freebie
  5. #ContestAlert
  6. #ContestEntry
  7. #instacontest
  8. #instagiveaway
  9. #WinIt
  10. #contest
  11. #GiveawayAlert
  12. #giveaway

The popular #tags for Reels

Are you the reels queen, or do you want to become the one? Then these below mentioned tags are for you. But don’t go for all of them because you can use only thirty of them. Pick it smartly!

  1. #ReelsInstagram
  2. #VideoOfTheDay
  3. #ReelsIndia
  4. #ReelSteady
  5. #disney
  6. #ForYouPage
  7. #InstagramReels
  8. #bhfyp
  9. #instareels
  10. #reelsinsta
  11. #fyp
  12. #ReelsOfInstagram
  13. #TikTokIndia
  14. #HolaReels
  15. #reels
  16. #ReelsBrasil
  17. #k
  18. #ReelsVideo
  19. #instareel
  20. #music

#tags for foodie

Do you love to eat and what to share your experience with another foodie on Instagram? If you are visiting any cafe, then before uploading, always add one of the following tags!

  1. #instafood
  2. #FoodBlogger
  3. #lunch
  4. #PicOfTheDay
  5. #instadaily
  6. #FoodPhotography
  7. #PhotoOfTheDay
  8. #food
  9. #healthy
  10. #foodie
  11. #FoodLover
  12. #bhfyp
  13. #instagood
  14. #tasty
  15. #delicious
  16. #foodstagram
  17. #homemade
  18. #cooking
  19. #FoodPorn
  20. #love
  21. #foodgasm
  22. #foodies
  23. #HealthyFood
  24. #dinner
  25. #yummy
  26. #restaurant

How to Pick the proper tags or find the best one for you?

There is a long list of each niche, and you can use all of them. If you are confused about what to pick and whatnot, here is the guide to choosing the perfect tag.

  1. Use the search function. Just mentions a keyword applicable to your content and choose the Tags tab. This handle will then provide you with a hashtags list. Search for relevant #tags with fair usage ( 50K)
  2. Use the tags that others use in your sector.

Study your competition. Review their post and study the tags they are using.

Seamus  Quitzon

Seamus Quitzon

1601341562

AWS Cost Allocation Tags and Cost Reduction

Bob had just arrived in the office for his first day of work as the newly hired chief technical officer when he was called into a conference room by the president, Martha, who immediately introduced him to the head of accounting, Amanda. They exchanged pleasantries, and then Martha got right down to business:

“Bob, we have several teams here developing software applications on Amazon and our bill is very high. We think it’s unnecessarily high, and we’d like you to look into it and bring it under control.”

Martha placed a screenshot of the Amazon Web Services (AWS) billing report on the table and pointed to it.

“This is a problem for us: We don’t know what we’re spending this money on, and we need to see more detail.”

Amanda chimed in, “Bob, look, we have financial dimensions that we use for reporting purposes, and I can provide you with some guidance regarding some information we’d really like to see such that the reports that are ultimately produced mirror these dimensions — if you can do this, it would really help us internally.”

“Bob, we can’t stress how important this is right now. These projects are becoming very expensive for our business,” Martha reiterated.

“How many projects do we have?” Bob inquired.

“We have four projects in total: two in the aviation division and two in the energy division. If it matters, the aviation division has 75 developers and the energy division has 25 developers,” the CEO responded.

Bob understood the problem and responded, “I’ll see what I can do and have some ideas. I might not be able to give you retrospective insight, but going forward, we should be able to get a better idea of what’s going on and start to bring the cost down.”

The meeting ended with Bob heading to find his desk. Cost allocation tags should help us, he thought to himself as he looked for someone who might know where his office is.

#aws #aws cloud #node js #cost optimization #aws cli #well architected framework #aws cost report #cost control #aws cost #aws tags

Christa  Stehr

Christa Stehr

1598408880

How To Unite AWS KMS with Serverless Application Model (SAM)

The Basics

AWS KMS is a Key Management Service that let you create Cryptographic keys that you can use to encrypt and decrypt data and also other keys. You can read more about it here.

Important points about Keys

Please note that the customer master keys(CMK) generated can only be used to encrypt small amount of data like passwords, RSA key. You can use AWS KMS CMKs to generate, encrypt, and decrypt data keys. However, AWS KMS does not store, manage, or track your data keys, or perform cryptographic operations with data keys.

You must use and manage data keys outside of AWS KMS. KMS API uses AWS KMS CMK in the encryption operations and they cannot accept more than 4 KB (4096 bytes) of data. To encrypt application data, use the server-side encryption features of an AWS service, or a client-side encryption library, such as the AWS Encryption SDK or the Amazon S3 encryption client.

Scenario

We want to create signup and login forms for a website.

Passwords should be encrypted and stored in DynamoDB database.

What do we need?

  1. KMS key to encrypt and decrypt data
  2. DynamoDB table to store password.
  3. Lambda functions & APIs to process Login and Sign up forms.
  4. Sign up/ Login forms in HTML.

Lets Implement it as Serverless Application Model (SAM)!

Lets first create the Key that we will use to encrypt and decrypt password.

KmsKey:
    Type: AWS::KMS::Key
    Properties: 
      Description: CMK for encrypting and decrypting
      KeyPolicy:
        Version: '2012-10-17'
        Id: key-default-1
        Statement:
        - Sid: Enable IAM User Permissions
          Effect: Allow
          Principal:
            AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
          Action: kms:*
          Resource: '*'
        - Sid: Allow administration of the key
          Effect: Allow
          Principal:
            AWS: !Sub arn:aws:iam::${AWS::AccountId}:user/${KeyAdmin}
          Action:
          - kms:Create*
          - kms:Describe*
          - kms:Enable*
          - kms:List*
          - kms:Put*
          - kms:Update*
          - kms:Revoke*
          - kms:Disable*
          - kms:Get*
          - kms:Delete*
          - kms:ScheduleKeyDeletion
          - kms:CancelKeyDeletion
          Resource: '*'
        - Sid: Allow use of the key
          Effect: Allow
          Principal:
            AWS: !Sub arn:aws:iam::${AWS::AccountId}:user/${KeyUser}
          Action:
          - kms:DescribeKey
          - kms:Encrypt
          - kms:Decrypt
          - kms:ReEncrypt*
          - kms:GenerateDataKey
          - kms:GenerateDataKeyWithoutPlaintext
          Resource: '*'

The important thing in above snippet is the KeyPolicy. KMS requires a Key Administrator and Key User. As a best practice your Key Administrator and Key User should be 2 separate user in your Organisation. We are allowing all permissions to the root users.

So if your key Administrator leaves the organisation, the root user will be able to delete this key. As you can see **KeyAdmin **can manage the key but not use it and KeyUser can only use the key. ${KeyAdmin} and **${KeyUser} **are parameters in the SAM template.

You would be asked to provide values for these parameters during SAM Deploy.

#aws #serverless #aws-sam #aws-key-management-service #aws-certification #aws-api-gateway #tutorial-for-beginners #aws-blogs