-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from baquan1708/feat/support-win
Update project template when creating with CLI
- Loading branch information
Showing
8 changed files
with
215 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Load environment variables from .env file (assuming you have a utility to load it) | ||
Get-Content .env | ForEach-Object { | ||
if ($_ -match "^\s*#") { | ||
return | ||
} | ||
if ($_ -match "^\s*(\w+)\s*=\s*(.*)\s*$") { | ||
$name = $matches[1] | ||
$value = $matches[2] | ||
$value = $value -replace '\s*#.*', '' | ||
[System.Environment]::SetEnvironmentVariable($name, $value, "Process") | ||
} | ||
} | ||
|
||
Write-Host "======= check if S3 bucket exists =======" | ||
$bucketExists = aws --endpoint-url=http://localhost:4566 s3 ls | Select-String $env:S3_BUCKET_NAME | ||
|
||
if (-not $bucketExists) { | ||
Write-Host "Bucket $env:S3_BUCKET_NAME does not exist. Creating it..." | ||
aws --endpoint-url=http://localhost:4566 s3 mb "s3://$env:S3_BUCKET_NAME" | ||
} else { | ||
Write-Host "Bucket $env:S3_BUCKET_NAME already exists." | ||
} | ||
|
||
Write-Host "======= list S3 buckets =======" | ||
aws --endpoint-url=http://localhost:4566 s3 ls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
# Load environment variables from .env file | ||
if [ -f .env ]; then | ||
export $(echo $(cat .env | sed 's/#.*//g' | xargs) | envsubst) | ||
fi | ||
|
||
echo "======= check if S3 bucket exists =======" | ||
bucket_exists=$(aws --endpoint-url=http://localhost:4566 s3 ls | grep "$S3_BUCKET_NAME" | wc -l) | ||
|
||
if [ "$bucket_exists" -eq 0 ]; then | ||
echo "Bucket $S3_BUCKET_NAME does not exist. Creating it..." | ||
aws --endpoint-url=http://localhost:4566 s3 mb s3://$S3_BUCKET_NAME | ||
else | ||
echo "Bucket $S3_BUCKET_NAME already exists." | ||
fi | ||
|
||
echo "======= list S3 buckets =======" | ||
aws --endpoint-url=http://localhost:4566 s3 ls |
133 changes: 133 additions & 0 deletions
133
packages/cli/templates/infra-local/scripts/trigger_ddb_stream.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# Set AWS environment variables | ||
$env:AWS_DEFAULT_REGION = "ap-northeast-1" | ||
$env:AWS_ACCOUNT_ID = "101010101010" | ||
$env:AWS_ACCESS_KEY_ID = "local" | ||
$env:AWS_SECRET_ACCESS_KEY = "local" | ||
|
||
$endpoint = "http://localhost:8000" | ||
|
||
# Load environment variables from .env file (assuming you have a utility to load it) | ||
Get-Content .env | ForEach-Object { | ||
if ($_ -match "^\s*#") { | ||
return | ||
} | ||
if ($_ -match "^\s*(\w+)\s*=\s*(.*)\s*$") { | ||
$name = $matches[1] | ||
$value = $matches[2] | ||
$value = $value -replace '\s*#.*', '' | ||
[System.Environment]::SetEnvironmentVariable($name, $value, "Process") | ||
} | ||
} | ||
|
||
Write-Host "Read table name" | ||
|
||
# Read table names from JSON file | ||
$tables = (Get-Content .\prisma\dynamodbs\cqrs.json | ConvertFrom-Json) | ||
|
||
# Check table health | ||
$start = Get-Date | ||
foreach ($table in $tables) { | ||
while ($true) { | ||
$elapsed = (New-TimeSpan -Start $start).TotalSeconds | ||
if ($elapsed -gt 10) { | ||
Write-Host "Timeout" | ||
exit 1 | ||
} | ||
|
||
Write-Host "Check health table local-$env:APP_NAME-$table-command" | ||
Write-Host "local-$env:APP_NAME-$table-command" | ||
$status = aws --endpoint $endpoint dynamodb describe-table --table-name "local-$env:APP_NAME-$table-command" --query "Table.TableStatus" | ||
|
||
Write-Host "Table status: $status" | ||
if ($status -eq '"ACTIVE"') { | ||
Write-Host "Table $table is ACTIVE" | ||
break | ||
} else { | ||
Write-Host "Table $table is not ACTIVE" | ||
Start-Sleep -Seconds 1 | ||
} | ||
} | ||
} | ||
|
||
# Check the health of 'tasks' table | ||
$start = Get-Date | ||
while ($true) { | ||
$elapsed = (New-TimeSpan -Start $start).TotalSeconds | ||
if ($elapsed -gt 10) { | ||
Write-Host "Timeout" | ||
exit 1 | ||
} | ||
|
||
Write-Host "Check health table tasks" | ||
$status = aws --endpoint $endpoint dynamodb describe-table --table-name "local-$env:APP_NAME-tasks" --query "Table.TableStatus" | ||
|
||
Write-Host "Table status: $status" | ||
if ($status -eq '"ACTIVE"') { | ||
Write-Host "Table tasks is ACTIVE" | ||
break | ||
} else { | ||
Write-Host "Table tasks is not ACTIVE" | ||
Start-Sleep -Seconds 1 | ||
} | ||
} | ||
|
||
# Wait for serverless to start | ||
$start = Get-Date | ||
while ($true) { | ||
$elapsed = (New-TimeSpan -Start $start).TotalSeconds | ||
if ($elapsed -gt 100) { | ||
Write-Host "Timeout" | ||
exit 1 | ||
} | ||
|
||
Write-Host "Check health serverless" | ||
try { | ||
$response = Invoke-WebRequest -Uri "http://localhost:3000" -UseBasicParsing -ErrorAction Stop | ||
$status = $response.StatusCode | ||
} catch { | ||
if ($_.Exception.Response -ne $null) { | ||
$status = $_.Exception.Response.StatusCode.Value__ | ||
} else { | ||
$status = 0 # Assign 0 or another value if there's no HTTP response (e.g., connection failure) | ||
} | ||
} | ||
|
||
Write-Host "Serverless status: $status" | ||
|
||
if ($status -eq 200) { | ||
Write-Host "Serverless is ACTIVE" | ||
break | ||
} else { | ||
Write-Host "Serverless is not ACTIVE" | ||
Start-Sleep -Seconds 1 | ||
} | ||
} | ||
|
||
|
||
# Trigger command stream | ||
$timestamp = [math]::Round((Get-Date).Subtract((Get-Date "01/01/1970")).TotalSeconds) | ||
foreach ($table in $tables) { | ||
Write-Host "Send a command to trigger command stream $table" | ||
$item = @{ | ||
pk = @{ S = "test" } | ||
sk = @{ S = "$timestamp" } | ||
} | ||
|
||
# Convert the item to a JSON string with double quotes | ||
$jsonItem = $item | ConvertTo-Json -Compress | ||
|
||
$jsonItemString = [string]$jsonItem | ||
|
||
$escapedJsonItemString = $jsonItemString -replace '"', '\"' | ||
|
||
Write-Host "Send a item to trigger command $table" | ||
|
||
aws dynamodb put-item --endpoint http://localhost:8000 --table-name "local-$env:APP_NAME-$table-command" --item $escapedJsonItemString | ||
} | ||
|
||
# Trigger asks stream | ||
Write-Host "Send a command to trigger command stream tasks" | ||
$command = @" | ||
aws dynamodb put-item --endpoint http://localhost:8000 --table-name "local-$env:APP_NAME-tasks" --item '{\"input\":{\"M\":{}},\"sk\":{\"S\":\"$timestamp\"},\"pk\":{\"S\":\"test\"}}' | ||
"@ | ||
Invoke-Expression $command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters