Skip to content

Lightspeed-Systems/aws-development-with-localstack

 
 

Repository files navigation

AWS CDK & Localstack (Local Development)

The cdk.json file tells the CDK Toolkit how to execute your app.

Useful commands

  • yarn build compile typescript to js
  • yarn lint check code style
  • yarn destroy destroy the current stack
  • yarn deploy deploy this stack to your default AWS account/region
  • yarn bootstrap clean up env

Install & Setup LocalStack

  1. Install Docker if you haven’t already. https://docs.docker.com/get-docker/
  2. Install AWS CLI. While we won’t be working with “real” AWS we will be using it to communicate with our local docker containers. https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html

Install AWS CDK Local

Avoid the mistake when we use cdk command maybe it can impact to real environment This lib provides a thin wrapper script cdklocal for using the AWS CDK library against local APIs provided by LocalStack. Refer : https://github.com/localstack/aws-cdk-local

npm install -g aws-cdk-local aws-cdk

Or yarn

yarn global add aws-cdk-local aws-cdk

$ cdklocal --version 1.65.5

Start Localstack & Deploy our services

Step 1. init create a fake aws credentials - use for our localstack as below ( This is required for our localstack )

cat ~/.aws/credentials

[default]
aws_access_key_id = test
aws_secret_access_key = test
region = us-west-2     
output = json

Step 2. cd to localstack folder and run the command docker-compose up -d

Open browser check our service http://localhost:4566/health

{
  "services": {
    "dynamodbstreams": "running", 
    "firehose": "running", 
    "kinesis": "running", 
    "s3": "running", 
    "ses": "running", 
    "sns": "running", 
    "sqs": "running", 
    "dynamodb": "running"
  }, "features": {"persistence": "initialized", "initScripts": "initialized"}
}

Step 3. Deploy our Application Stack

yarn deploy
IAM Statement Changes ...
┌───┬───────────────────────┬────────┬─────────────────┬───────────────────────────┬───────────────────────────────────────────────────────┐
│   │ Resource              │ Effect │ Action          │ Principal                 │ Condition                                             │
├───┼───────────────────────┼────────┼─────────────────┼───────────────────────────┼───────────────────────────────────────────────────────┤
│ + │ ${SampleAppQueue.Arn} │ Allow  │ sqs:SendMessage │ Service:sns.amazonaws.com │ "ArnEquals": {                                        │
│   │                       │        │                 │                           │   "aws:SourceArn": "${SampleAppTopic}"                │
│   │                       │        │                 │                           │ }                                                     │
└───┴───────────────────────┴────────┴─────────────────┴───────────────────────────┴───────────────────────────────────────────────────────┘
(NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)

Do you wish to deploy these changes (y/n)?

#### Type `y` and see our stack

ApplicationStack: deploying...
ApplicationStack: creating CloudFormation changeset...


✅  ApplicationStack

Stack ARN:
    arn:aws:cloudformation:us-west-2:000000000000:stack/ApplicationStack/e67d04e2

Step 4. Quick check our deployment S3 & Dynamo DB Tables

DynamoDB

aws --endpoint-url=http://localhost:4566 dynamodb list-tables

{
    "TableNames": [
        "test-development"
    ]
}

aws --endpoint-url=http://localhost:4566 dynamodb describe-table --table-name test-development

Useful Tools ( How to use it )

Tool Description
S3 Viewer (MAC & Win)
https://cyberduck.io/
Screen Shot 2021-10-08 at 17 39 59
DynamoDB Viewer (MAC & Win)
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/workbench.settingup.html
Screen Shot 2021-10-08 at 17 42 30
SQS Sender
https://github.com/kobee-tech-stack/sqs-viewer

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 95.6%
  • JavaScript 4.4%