Skip to content

Commit

Permalink
note update
Browse files Browse the repository at this point in the history
- aws exec
- aws nuke
- dm set
  • Loading branch information
xy-241 committed Dec 21, 2023
1 parent 91440c8 commit 808d0fe
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 49 deletions.
48 changes: 37 additions & 11 deletions content/Discrete Math/Set.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Author Profile:
tags:
- discrete_math
Creation Date: 2023-12-18, 10:33
Last Date: 2023-12-20T10:36:56+08:00
Last Date: 2023-12-21T10:02:37+08:00
References:
---
## Abstract
Expand Down Expand Up @@ -41,7 +41,7 @@ $$
$$
\{x \in U | P(x)\}
$$
- The set of all `x` in `U` such that `P(x)`` is true
- The set of all `x` in `U` such that `P(x)` is true

### Replacement Notation
$$
Expand All @@ -68,13 +68,8 @@ $$
- The size of the [[Discrete Math/Set|Set]]



## Terminologies
## Types of Sets
---
### Object
- Members or elements of [[Discrete Math/Set|Set]]
- Example: `1`, `2`, `3` are objects in the set of [[Integer (整数)]]

### Subset
$$
A \subseteq B
Expand All @@ -87,14 +82,45 @@ $$
$$
B \supseteq A
$$
- `B` is the supper `A`
- `A` is a [[#Subset]] of `B`


### Proper Subset
$$
A \subseteq B
A \subsetneq B
$$
iff
$$
(A \subseteq B) \land (A \ne B)
$$
$$

### Empty Set
$$
\emptyset
$$
$$
\{\}
$$
- A [[Discrete Math/Set|Set]] that contains `0` [[#Object]]
- Itself is a [[#Object]]
>[!caution] Not a **Null Set**
### Singleton
- A [[Discrete Math/Set|Set]] with exactly one [[#Object]]


## Theorems
---
### Theorem 6.2.4
- An [[#Empty Set]] is a s [[#Subset]] of every [[Discrete Math/Set|Set]]
- Assume `A` is all the possible sets
$$
\emptyset \subseteq A
$$
- Proved using [[Mathematical Statement#Vacuous Truth of Universal]]
## Terminologies
---
### Object
- Members or elements of [[Discrete Math/Set|Set]]
- Example: `1`, `2`, `3` are objects in the set of [[Integer (整数)]]

33 changes: 20 additions & 13 deletions content/Tools/AWS/AWS Nuke.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,33 @@ Author Profile:
tags:
- aws
Creation Date: 2023-08-01T16:41:00
Last Date: 2023-12-18T14:01:20+08:00
Last Date: 2023-12-21T10:35:12+08:00
---
## Abstract
---
- A tool to remove *all resources* in an AWS Account automatically without manually clicking countless buttons
A tool to remove *all resources* in an AWS Account automatically without manually clicking countless buttons

Refer to [Github Repo](https://github.com/rebuy-de/aws-nuke#caution) for more details

>[!CAUTION] Always double check what resources that AWS Nuke aren't able to remove
>- There are a few resources that require manual removal like *AWS Network Firewall*

Setup Checklist:
- [ ] [[#AWS Account Setting]]
- [ ] [[#AWS Nuke Configuration File]]
- [ ] [[#Run in Docker]]
## AWS Account Setting
---
- We need to create **Account Alias** in order to start using `aws-nuke`
We need to create **Account Alias** in order to start using `aws-nuke`
![[account_alias.png]]
- Refer to [Github Repo](https://github.com/rebuy-de/aws-nuke) for more details


## config.yml (Configuration File)

## AWS Nuke Configuration File
---
We are using a `.yml` to configure the behaviour of `aws-nuke`
### Example 1: Remove all
```yaml
```yaml /<YOUR_ACCOUNT_NUMBER>/
regions:
- "ap-southeast-1"
account-blocklist:
Expand All @@ -37,9 +44,9 @@ accounts:
>[!caution] Yaml Syntax
>Make sure there is a **space** between `:` and `{}`
### Example 2: Filter resources
- Prevent some resources from be removed
```yaml
# Achieve this: ap-southeast-1 - ACMCertificate - arn:aws:acm:ap-southeast-1:106330972965:certificate/5212c31a-94f1-4dc9-80a8-b72d8d6b2054 - [DomainName: "vault.yxy.ninja"] - filtered by config
Prevent some resources from be removed
```yaml /<YOUR_ACCOUNT_NUMBER>/ {9-11}
# Achieve this: ap-southeast-1 - ACMCertificate - arn:aws:acm:ap-southeast-1:106330972960:certificate/5212c31a-94f1-4dc9-80a8-b72d8d6b2054 - [DomainName: "vault.yxy.ninja"] - filtered by config
regions:
- "ap-southeast-1"
Expand All @@ -49,13 +56,13 @@ accounts:
"<YOUR_ACCOUNT_NUMBER>":
filters:
ACMCertificate:
- "arn:aws:acm:ap-southeast-1:106330972965:certificate/5212c31a-94f1-4dc9-80a8-b72d8d6b2054"
- "arn:aws:acm:ap-southeast-1:106330972960:certificate/5212c31a-94f1-4dc9-80a8-b72d8d6b2054"
```

## Run in [[Docker]]
---
- Pass in the [[#config.yml (Configuration File)]] & AWS Profile to the container using [[Docker Volume]]
```bash
Pass in the [[#AWS Nuke Configuration File]] & **AWS Credentials** to the container using [[Docker Volume]]
```bash /<ABSOLUTE_PATH_TO_CONFIG.YAML>/ /<ABSOLUTE_PATH_TO_.aws>/ /<YOUR_AWS_PROFILE>/
docker run \
--rm -it \
-v <ABSOLUTE_PATH_TO_CONFIG.YAML>:/home/aws-nuke/config.yml \
Expand Down
56 changes: 31 additions & 25 deletions content/Tools/AWS/Compute/ECS/ECS Exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,55 @@ Author Profile:
tags:
- aws
Creation Date: 2023-09-04T11:16:00
Last Date: 2023-12-14T18:27:12+08:00
Last Date: 2023-12-21T10:41:05+08:00
References:
---
## Abstract
---
- Obtain a **shell** into [[ECS]] from a local machine
**SSH** into [[ECS#Container]] from your own laptops. Great for debugging containers under ECS.

## Enable ECS Exec for [[ECS]]
**Setup Checklist:**
- [ ] [[#Enable ECS Exec]]
- [ ] [[#Install Session Manager Plugin for AWS Cli]]
- [ ] [[#Add SSM permission via IAM Policy to the ECS Role]]
- [ ] [[#Check if ECS Exec is configured properly]]
- [ ] [[#SSH into ECS Container]]

## Enable ECS Exec
---
### Existing [[ECS]]
>[!caution] Only new [[ECS#Task]] under the [[ECS#Service]] will have the ECS Exec enabled
```bash
### For Existing ECS Cluster
- Only new [[ECS#Task]] under the [[ECS#Service]] will have the ECS Exec enabled
```bash "<CLUSTER_NAME>" "<SERVICE_NAME>"
aws ecs update-service \
--cluster <CLUSTER_NAME> \
--service <SERVICE_NAME> \
--enable-execute-command
```


### New [[ECS]]
>[!info] Based on what I know, there isn't a way to enable ECS EXEC from the GUI console
### New ECS Cluster
Based on what I know, there isn't a way to enable ECS EXEC from the GUI console

Option 1. [Using Terraform](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_service#enable_execute_command)
- **Option 1:** [Using Terraform](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_service#enable_execute_command)

Option 2. Using Cli
```bash
- **Option 2:** Using Cli
```bash /<CLUSTER_NAME>/ /<TASK-DEFINITION-NAME>/ /<SERVICE_NAME>/ /1/
aws ecs create-service \
--cluster cluster-name \
--task-definition task-definition-name \
--cluster <CLUSTER_NAME> \
--task-definition <TASK-DEFINITION-NAME> \
--enable-execute-command \
--service-name service-name \
--service-name <SERVICE_NAME> \
--desired-count 1
```

## Obtain a Shell
## Get into ECS Container
---
### Install [[Session Manager]] plugin for AWS Cli
### Install Session Manager Plugin for AWS Cli
```bash
brew install --cask session-manager-plugin
```

### Add SSM permission ([[IAM Policy]]) to the ECS Role
>[!caution] NOT the execution role
### Add SSM permission via IAM Policy to the ECS Role
**NOT the execution role!!!**

```json
{
Expand All @@ -68,22 +74,22 @@ brew install --cask session-manager-plugin
}
```

### Check if ECS Exec is enabled on the [[ECS#Task]]
- [Script is open-sourced](https://github.com/aws-containers/amazon-ecs-exec-checker)
```bash
### Check if ECS Exec is configured properly
Script is [open-sourced](https://github.com/aws-containers/amazon-ecs-exec-checker)
```bash /<PROFILE_NAME>/ /<AWS_REGION>/ /<CLUSTER_NAME>/ /<TASK_ID>/
export AWS_PROFILE=<PROFILE_NAME>
export AWS_REGION=<AWS_REGION>

bash <( curl -Ls https://raw.githubusercontent.com/aws-containers/amazon-ecs-exec-checker/main/check-ecs-exec.sh ) <CLUSTER_NAME> <TASK_ID>
```

### SSH into [[ECS#Container]]
```bash
### SSH into ECS Container
If face error connecting, can try create a new [[ECS#Task]] deployment
```bash /<CLUSTER_NAME>/ /<TASK_ID>/ /<CONTAINER_NAME>/
aws ecs execute-command \
--cluster <CLUSTER_NAME> \
--task <TASK_ID> \
--container <CONTAINER_NAME> \
--interactive \
--command "/bin/sh"
```
>[!tip] If face error connecting, can try create a new [[ECS#Task]] deployment

0 comments on commit 808d0fe

Please sign in to comment.