aws-development-with-localstack
aws-development-with-localstack copied to clipboard
AWS CDK & Localstack (Local Development)

A few benefits of this approach are
- You can run the lambda function locally
- Donβt impact your team by sharing the same env ( update on the same buckets, same records )
- Debug & Speed up your working
- Donβt need to worry about paying for AWS usage for stupid action π₯°
The cdk.json file tells the CDK Toolkit how to execute your app.
Useful commands
yarn buildcompile typescript to jsyarn lintcheck code styleyarn destroydestroy the current stackyarn deploydeploy this stack to your default AWS account/regionyarn bootstrapclean up env
Install & Setup LocalStack
- Install Docker if you havenβt already. https://docs.docker.com/get-docker/
- 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"}
}
Check your memcached was run successfully :check_mark:
# telnet the to port 11211
telnet localhost 11211
# Add a new key to memcache
set Customer_Id 0 900 5
# Type your value ( Enter - A message STORED will be displayed)
00-000-000
STORED
# Recheck by get your key stored
get Customer_Id
00-000-000
# exit telnet
quit
Check your Redis was run successfully :check_mark:
Install Redis Client ( Add connection )
Windows
Download latest https://github.com/qishibo/AnotherRedisDesktopManager/releases package from https://github.com/qishibo/AnotherRedisDesktopManager/releases [or gitee in China], double click to install.
Or by winget: winget install qishibo.AnotherRedisDesktopManager
Mac
Download latest https://github.com/qishibo/AnotherRedisDesktopManager/releases package from release [or gitee in China], double click to install.
Or by brew: brew install --cask another-redis-desktop-manager
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/ |
![]() |
| DynamoDB Viewer (MAC & Win) https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/workbench.settingup.html |
![]() |
| SQS Sender https://github.com/kobee-tech-stack/sqs-viewer |
|
| Redis Viewer (MAC & Win) https://github.com/qishibo/AnotherRedisDesktopManager |
... |

