[go: up one dir, main page]

Skip to content

Commit

Permalink
move policies to a common folder
Browse files Browse the repository at this point in the history
  • Loading branch information
sannya-singal committed May 28, 2024
1 parent 8feb7dd commit f302728
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ Create the SQS queue in Account A and set the policy to allow Account C to send

```bash
QUEUE_URL=$(awslocal sqs create-queue --queue-name $QUEUE_NAME --attributes VisibilityTimeout=300 --query 'QueueUrl' --output text)
awslocal sqs set-queue-attributes --queue-url $QUEUE_URL --attributes file://sqs-policy1.json
awslocal sqs set-queue-attributes --queue-url $QUEUE_URL --attributes file://policy/sqs-policy1.json
```

Create the S3 bucket in Account A and set the policy to allow Account C to upload files to the bucket in Account A:

```bash
awslocal s3api create-bucket --bucket $BUCKET_NAME
awslocal s3api put-bucket-policy --bucket $BUCKET_NAME --policy file://s3-policy1.json
awslocal s3api put-bucket-policy --bucket $BUCKET_NAME --policy file://policy/s3-policy1.json
```

## Create the SQS queue and S3 bucket in Account B
Expand All @@ -81,14 +81,14 @@ Create the SQS queue in Account B and set the policy to allow Account C to send

```bash
QUEUE_URL=$(awslocal sqs create-queue --queue-name $QUEUE_NAME --region eu-west-1 --attributes VisibilityTimeout=300 --query 'QueueUrl' --output text)
awslocal sqs set-queue-attributes --queue-url $QUEUE_URL --attributes file://sqs-policy2.json
awslocal sqs set-queue-attributes --queue-url $QUEUE_URL --attributes file://policy/sqs-policy2.json
```

Create the S3 bucket in Account B and set the policy to allow Account C to upload files to the bucket in Account B:

```bash
awslocal s3api create-bucket --bucket $BUCKET_NAME
awslocal s3api put-bucket-policy --bucket $BUCKET_NAME --policy file://s3-policy2.json
awslocal s3api put-bucket-policy --bucket $BUCKET_NAME --policy file://policy/s3-policy2.json
```

## Create the Lambda function and API Gateway in Account C
Expand All @@ -103,8 +103,8 @@ export AWS_SECRET_ACCESS_KEY=test
Create lambda execution role and attach it to the policy:

```bash
awslocal iam create-role --role-name common-lambda-role --assume-role-policy-document file://trust-policy.json
awslocal iam put-role-policy --role-name common-lambda-role --policy-name common-lambda-policy --policy-document file://lambda-policy.json
awslocal iam create-role --role-name common-lambda-role --assume-role-policy-document file://policy/trust-policy.json
awslocal iam put-role-policy --role-name common-lambda-role --policy-name common-lambda-policy --policy-document file://policy/lambda-policy.json
```

Create the deployment package for the Lambda function and create the function:
Expand Down
4 changes: 2 additions & 2 deletions accountA.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ QUEUE_URL=$(awslocal sqs create-queue --queue-name $QUEUE_NAME --attributes Visi
echo "Queue created URL: $QUEUE_URL"

echo "> Setting Queue Policy for $QUEUE_URL..."
awslocal sqs set-queue-attributes --queue-url $QUEUE_URL --attributes file://sqs-policy1.json
awslocal sqs set-queue-attributes --queue-url $QUEUE_URL --attributes file://policy/sqs-policy1.json

echo "> Creating Bucket: $BUCKET_NAME..."
awslocal s3api create-bucket --bucket $BUCKET_NAME
echo "Bucket created: $BUCKET_NAME"

echo "> Setting Bucket Policy for $BUCKET_NAME..."
awslocal s3api put-bucket-policy --bucket $BUCKET_NAME --policy file://s3-policy1.json
awslocal s3api put-bucket-policy --bucket $BUCKET_NAME --policy file://policy/s3-policy1.json

echo "Setup completed for Account ID: $ACCOUNT_ID"
4 changes: 2 additions & 2 deletions accountB.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ echo "> Creating Queue: $QUEUE_NAME..."
QUEUE_URL=$(awslocal sqs create-queue --queue-name $QUEUE_NAME --region eu-west-1 --attributes VisibilityTimeout=300 --query 'QueueUrl' --output text)
echo "Queue created URL: $QUEUE_URL"
echo "> Setting Queue Policy for $QUEUE_URL..."
awslocal sqs set-queue-attributes --queue-url $QUEUE_URL --attributes file://sqs-policy2.json
awslocal sqs set-queue-attributes --queue-url $QUEUE_URL --attributes file://policy/sqs-policy2.json

echo "> Creating Bucket: $BUCKET_NAME..."
awslocal s3api create-bucket --bucket $BUCKET_NAME
echo "Bucket created: $BUCKET_NAME"
echo "> Setting Bucket Policy for $BUCKET_NAME..."
awslocal s3api put-bucket-policy --bucket $BUCKET_NAME --policy file://s3-policy2.json
awslocal s3api put-bucket-policy --bucket $BUCKET_NAME --policy file://policy/s3-policy2.json

echo "Setup completed for Account ID: $ACCOUNT_ID"
5 changes: 2 additions & 3 deletions accountC.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export AWS_ACCESS_KEY_ID=333333333333
export AWS_SECRET_ACCESS_KEY=test

awslocal iam create-role --role-name common-lambda-role --assume-role-policy-document file://trust-policy.json
awslocal iam put-role-policy --role-name common-lambda-role --policy-name common-lambda-policy --policy-document file://lambda-policy.json
awslocal iam create-role --role-name common-lambda-role --assume-role-policy-document file://policy/trust-policy.json
awslocal iam put-role-policy --role-name common-lambda-role --policy-name common-lambda-policy --policy-document file://policy/lambda-policy.json

zip lambda_function.zip lambda_function.py

Expand Down Expand Up @@ -34,4 +34,3 @@ awslocal lambda add-permission \
--principal apigateway.amazonaws.com \
--source-arn "arn:aws:execute-api:us-east-1:333333333333:$API_ID/*/*/*" \
--source-account 333333333333

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f302728

Please sign in to comment.