-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-localstack.sh
More file actions
executable file
·74 lines (57 loc) · 1.8 KB
/
init-localstack.sh
File metadata and controls
executable file
·74 lines (57 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
set -e
# Create DynamoDB table
awslocal dynamodb create-table \
--table-name order \
--attribute-definitions AttributeName=orderId,AttributeType=S \
--key-schema AttributeName=orderId,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
# Create SQS queue
awslocal sqs create-queue --queue-name order-queue
# Create S3 bucket
awslocal s3 mb s3://invoices
# Create SNS topic
awslocal sns create-topic --name order-notifications
# Subscriptions
set -e
# Names
TOPIC_NAME="order-created-topic"
QUEUE_NAME="order-created-queue"
# Create SNS topic
TOPIC_ARN=$(awslocal sns create-topic --name "$TOPIC_NAME" --query 'TopicArn' --output text)
echo "Created SNS topic: $TOPIC_ARN"
# Create SQS queue
QUEUE_URL=$(awslocal sqs create-queue --queue-name "$QUEUE_NAME" --query 'QueueUrl' --output text)
echo "Created SQS queue: $QUEUE_URL"
# Get SQS Queue ARN
QUEUE_ARN=$(awslocal sqs get-queue-attributes --queue-url "$QUEUE_URL" --attribute-names QueueArn --query 'Attributes.QueueArn' --output text)
# Allow SNS to send messages to SQS (set proper policy)
POLICY=$(cat <<EOF
{
"Version": "2012-10-17",
"Statement": [{
"Sid": "Allow-SNS-SendMessage",
"Effect": "Allow",
"Principal": "*",
"Action": "SQS:SendMessage",
"Resource": "$QUEUE_ARN",
"Condition": {
"ArnEquals": {
"aws:SourceArn": "$TOPIC_ARN"
}
}
}]
}
EOF
)
awslocal sqs set-queue-attributes \
--queue-url "$QUEUE_URL" \
--attributes Policy="$(echo "$POLICY" | jq -c .)"
echo "Set SQS queue policy to allow SNS publishing."
# Subscribe SQS queue to SNS topic
awslocal sns subscribe \
--topic-arn "$TOPIC_ARN" \
--protocol sqs \
--notification-endpoint "$QUEUE_ARN"
echo "Subscribed SQS queue to SNS topic."
echo "LocalStack resources initialized successfully!"