'AWS'에 해당되는 글 22건

  1. 2020.03.13 [AWS] aws iot/iot-data 등등
  2. 2020.03.12 [AWS] 아마존 리눅스 & 우분투 타임존 변경
  3. 2020.03.04 [AWS] ..user is not authorized to perform: iam:PassRole on resource.. 에러 시
  4. 2020.03.03 [AWS IoT] CA 인증서 등록
  5. 2020.02.26 [AWS] ssh tunneling on ec2
  6. 2020.02.25 [AWS] VPC 부터 EC2 생성해서 SSH 연결해보기
  7. 2018.08.28 [Logstash] AWS SQS + Logstash 구성
  8. 2017.02.02 [AWS] ELB + http to https + Nginx 설정
  9. 2016.06.24 [AWS] Instance register/deregister on AWS ELB
  10. 2016.06.07 [AWS] JVM 타임존 설정 이슈

[AWS] aws iot/iot-data 등등

Cloud&Container/AWS 2020. 3. 13. 16:58

개발 진행을 하다 보면 대 부분 레퍼런스 문서와 API 문서를 안 볼 수가 없습니다.

더군다나 제공 하는 모든 API 를 다 기억 할 수도 없구요.

그래서 그냥 한 눈에 보기 편하게 모아 두었습니다.

 

[aws iot cli command]

https://docs.aws.amazon.com/cli/latest/reference/iot/index.html

accept-certificate-transfer              | add-thing-to-billing-group
add-thing-to-thing-group                 | associate-targets-with-job
attach-policy                            | attach-principal-policy
attach-security-profile                  | attach-thing-principal
cancel-audit-mitigation-actions-task     | cancel-audit-task
cancel-certificate-transfer              | cancel-job
cancel-job-execution                     | clear-default-authorizer
confirm-topic-rule-destination           | create-authorizer
create-billing-group                     | create-certificate-from-csr
create-domain-configuration              | create-dynamic-thing-group
create-job                               | create-keys-and-certificate
create-mitigation-action                 | create-ota-update
create-policy                            | create-policy-version
create-provisioning-claim                | create-provisioning-template
create-provisioning-template-version     | create-role-alias
create-scheduled-audit                   | create-security-profile
create-stream                            | create-thing
create-thing-group                       | create-thing-type
create-topic-rule                        | create-topic-rule-destination
delete-account-audit-configuration       | delete-authorizer
delete-billing-group                     | delete-ca-certificate
delete-certificate                       | delete-domain-configuration
delete-dynamic-thing-group               | delete-job
delete-job-execution                     | delete-mitigation-action
delete-ota-update                        | delete-policy
delete-policy-version                    | delete-provisioning-template
delete-provisioning-template-version     | delete-registration-code
delete-role-alias                        | delete-scheduled-audit
delete-security-profile                  | delete-stream
delete-thing                             | delete-thing-group
delete-thing-type                        | delete-topic-rule
delete-topic-rule-destination            | delete-v2-logging-level
deprecate-thing-type                     | describe-account-audit-configuration
describe-audit-finding                   | describe-audit-mitigation-actions-task
describe-audit-task                      | describe-authorizer
describe-billing-group                   | describe-ca-certificate
describe-certificate                     | describe-default-authorizer
describe-domain-configuration            | describe-endpoint
describe-event-configurations            | describe-index
describe-job                             | describe-job-execution
describe-mitigation-action               | describe-provisioning-template
describe-provisioning-template-version   | describe-role-alias
describe-scheduled-audit                 | describe-security-profile
describe-stream                          | describe-thing
describe-thing-group                     | describe-thing-registration-task
describe-thing-type                      | detach-policy
detach-principal-policy                  | detach-security-profile
detach-thing-principal                   | disable-topic-rule
enable-topic-rule                        | get-cardinality
get-effective-policies                   | get-indexing-configuration
get-job-document                         | get-logging-options
get-ota-update                           | get-percentiles
get-policy                               | get-policy-version
get-registration-code                    | get-statistics
get-topic-rule                           | get-topic-rule-destination
get-v2-logging-options                   | list-active-violations
list-attached-policies                   | list-audit-findings
list-audit-mitigation-actions-executions | list-audit-mitigation-actions-tasks
list-audit-tasks                         | list-authorizers
list-billing-groups                      | list-ca-certificates
list-certificates                        | list-certificates-by-ca
list-domain-configurations               | list-indices
list-job-executions-for-job              | list-job-executions-for-thing
list-jobs                                | list-mitigation-actions
list-ota-updates                         | list-outgoing-certificates
list-policies                            | list-policy-principals
list-policy-versions                     | list-principal-policies
list-principal-things                    | list-provisioning-template-versions
list-provisioning-templates              | list-role-aliases
list-scheduled-audits                    | list-security-profiles
list-security-profiles-for-target        | list-streams
list-tags-for-resource                   | list-targets-for-policy
list-targets-for-security-profile        | list-thing-groups
list-thing-groups-for-thing              | list-thing-principals
list-thing-registration-task-reports     | list-thing-registration-tasks
list-thing-types                         | list-things
list-things-in-billing-group             | list-things-in-thing-group
list-topic-rule-destinations             | list-topic-rules
list-v2-logging-levels                   | list-violation-events
register-ca-certificate                  | register-certificate
register-thing                           | reject-certificate-transfer
remove-thing-from-billing-group          | remove-thing-from-thing-group
replace-topic-rule                       | search-index
set-default-authorizer                   | set-default-policy-version
set-logging-options                      | set-v2-logging-level
set-v2-logging-options                   | start-audit-mitigation-actions-task
start-on-demand-audit-task               | start-thing-registration-task
stop-thing-registration-task             | tag-resource
test-authorization                       | test-invoke-authorizer
transfer-certificate                     | untag-resource
update-account-audit-configuration       | update-authorizer
update-billing-group                     | update-ca-certificate
update-certificate                       | update-domain-configuration
update-dynamic-thing-group               | update-event-configurations
update-indexing-configuration            | update-job
update-mitigation-action                 | update-provisioning-template
update-role-alias                        | update-scheduled-audit
update-security-profile                  | update-stream
update-thing                             | update-thing-group
update-thing-groups-for-thing            | update-topic-rule-destination
validate-security-profile-behaviors      | help

 

[aws iot-data cli command]

https://docs.aws.amazon.com/cli/latest/reference/iot-data/index.html

delete-thing-shadow                      | get-thing-shadow
publish                                  | update-thing-shadow
help

 

[aws iot-jobs-data cli command]

https://docs.aws.amazon.com/cli/latest/reference/iot-jobs-data/index.html

describe-job-execution                   | get-pending-job-executions
start-next-pending-job-execution         | update-job-execution

 

[aws iot1click-devices cli command]

https://docs.aws.amazon.com/cli/latest/reference/iot1click-devices/index.html

claim-devices-by-claim-code              | describe-device
finalize-device-claim                    | get-device-methods
initiate-device-claim                    | invoke-device-method
list-device-events                       | list-devices
list-tags-for-resource                   | tag-resource
unclaim-device                           | untag-resource
update-device-state                      | help

 

[aws iot1click-projects cli command]

https://docs.aws.amazon.com/cli/latest/reference/iot1click-projects/index.html

associate-device-with-placement          | create-placement
create-project                           | delete-placement
delete-project                           | describe-placement
describe-project                         | disassociate-device-from-placement
get-devices-in-placement                 | list-placements
list-projects                            | list-tags-for-resource
tag-resource                             | untag-resource
update-placement                         | update-project
help

 

[aws iotanalytics cli command]

https://docs.aws.amazon.com/cli/latest/reference/iotanalytics/index.html

batch-put-message                        | cancel-pipeline-reprocessing
create-channel                           | create-dataset
create-dataset-content                   | create-datastore
create-pipeline                          | delete-channel
delete-dataset                           | delete-dataset-content
delete-datastore                         | delete-pipeline
describe-channel                         | describe-dataset
describe-datastore                       | describe-logging-options
describe-pipeline                        | get-dataset-content
list-channels                            | list-dataset-contents
list-datasets                            | list-datastores
list-pipelines                           | list-tags-for-resource
put-logging-options                      | run-pipeline-activity
sample-channel-data                      | start-pipeline-reprocessing
tag-resource                             | untag-resource
update-channel                           | update-dataset
update-datastore                         | update-pipeline
help

 

[aws iotevents cli command]

https://docs.aws.amazon.com/cli/latest/reference/iotevents/index.html

create-detector-model                    | create-input
delete-detector-model                    | delete-input
describe-detector-model                  | describe-input
describe-logging-options                 | list-detector-model-versions
list-detector-models                     | list-inputs
list-tags-for-resource                   | put-logging-options
tag-resource                             | untag-resource
update-detector-model                    | update-input
help

 

[aws iotevents-data cli command]

https://docs.aws.amazon.com/cli/latest/reference/iotevents-data/index.html

batch-put-message                        | batch-update-detector
describe-detector                        | list-detectors
help

 

[aws iotsecuretunneling cli command]

https://docs.aws.amazon.com/cli/latest/reference/iotsecuretunneling/index.html

close-tunnel                             | describe-tunnel
list-tags-for-resource                   | list-tunnels
open-tunnel                              | tag-resource
untag-resource                           | help

 

[aws iotthingsgraph cli command]

https://docs.aws.amazon.com/cli/latest/reference/iotthingsgraph/index.html

associate-entity-to-thing                | create-flow-template
create-system-instance                   | create-system-template
delete-flow-template                     | delete-namespace
delete-system-instance                   | delete-system-template
deploy-system-instance                   | deprecate-flow-template
deprecate-system-template                | describe-namespace
dissociate-entity-from-thing             | get-entities
get-flow-template                        | get-flow-template-revisions
get-namespace-deletion-status            | get-system-instance
get-system-template                      | get-system-template-revisions
get-upload-status                        | list-flow-execution-messages
list-tags-for-resource                   | search-entities
search-flow-executions                   | search-flow-templates
search-system-instances                  | search-system-templates
search-things                            | tag-resource
undeploy-system-instance                 | untag-resource
update-flow-template                     | update-system-template
upload-entity-definitions                | help

 

:

[AWS] 아마존 리눅스 & 우분투 타임존 변경

Cloud&Container/AWS 2020. 3. 12. 21:20

https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/set-time.html

 

문서 보고 잘 따라 하시면 됩니다. :)

Amazon Linux AMI에서 Amazon Time Sync Service 구성

Amazon Time Sync Service를 사용하도록 인스턴스를 구성하려면

  1. 인스턴스를 연결하고 NTP 서비스를 제거합니다.

     

    [ec2-user ~]$ sudo yum erase 'ntp*'
  2. chrony 패키지를 설치합니다.

     

    [ec2-user ~]$ sudo yum install chrony
  3. vim 또는 nano과 같은 텍스트 편집기를 사용하여 /etc/chrony.conf 파일을 엽니다. 파일이 다음 라인을 포함하고 있는지 확인합니다.

     

    server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4

    이 라인이 존재할 경우, Amazon Time Sync Service가 이미 구성된 상태이기 때문에 다음 단계로 넘어갈 수 있습니다. 라인이 없는 경우에는 파일에 이미 존재하는 다른 server 또는 pool 문 뒤에 라인을 추가하고 변경 사항을 저장합니다.

  4. chrony 데몬(chronyd)을 다시 시작합니다.

     

    [ec2-user ~]$ sudo service chronyd restartStarting chronyd: [ OK ]

    참고

    RHEL 및 CentOS(최대 버전 6까지)에서 서비스 이름은 chrony이 아니라 chronyd입니다.

  5. chkconfig 명령을 사용해서 매번 시스템이 부팅할 때마다 시작되도록 chronyd를 구성합니다.

     

    [ec2-user ~]$ sudo chkconfig chronyd on
  6. chrony가 169.254.169.123 IP 주소를 사용하여 시간을 동기화하고 있는지 확인합니다.

     

    [ec2-user ~]$ chronyc sources -v210 Number of sources = 7 .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current synced, '+' = combined , '-' = not combined, | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable. || .- xxxx [ yyyy ] +/- zzzz || Reachability register (octal) -. | xxxx = adjusted offset, || Log2(Polling interval) --. | | yyyy = measured offset, || \ | | zzzz = estimated error. || | | \ MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* 169.254.169.123 3 6 17 43 -30us[ -226us] +/- 287us ^- ec2-12-34-231-12.eu-west> 2 6 17 43 -388us[ -388us] +/- 11ms ^- tshirt.heanet.ie 1 6 17 44 +178us[ +25us] +/- 1959us ^? tbag.heanet.ie 0 6 0 - +0ns[ +0ns] +/- 0ns ^? bray.walcz.net 0 6 0 - +0ns[ +0ns] +/- 0ns ^? 2a05:d018:c43:e312:ce77:> 0 6 0 - +0ns[ +0ns] +/- 0ns ^? 2a05:d018:dab:2701:b70:b> 0 6 0 - +0ns[ +0ns] +/- 0ns

    반환된 출력에서 ^*는 기본 설정된 타임 소스를 나타냅니다.

  7. chrony에서 보고된 시간 동기화 지표를 확인합니다.

     

    [ec2-user ~]$ chronyc trackingReference ID : A9FEA97B (169.254.169.123) Stratum : 4 Ref time (UTC) : Wed Nov 22 13:18:34 2017 System time : 0.000000626 seconds slow of NTP time Last offset : +0.002852759 seconds RMS offset : 0.002852759 seconds Frequency : 1.187 ppm fast Residual freq : +0.020 ppm Skew : 24.388 ppm Root delay : 0.000504752 seconds Root dispersion : 0.001112565 seconds Update interval : 64.4 seconds Leap status : Normal

Ubuntu에서 Amazon Time Sync Service 구성

Amazon Time Sync Service를 사용하도록 인스턴스를 구성하려면

  1. 인스턴스를 연결해 apt를 사용하여 chrony 패키지를 설치합니다.

     

    ubuntu:~$ sudo apt install chrony

    참고

    필요할 경우 sudo apt update를 실행하여 먼저 인스턴스를 업데이트합니다.

  2. vim 또는 nano과 같은 텍스트 편집기를 사용하여 /etc/chrony/chrony.conf 파일을 엽니다. 파일에 이미 존재하는 server 또는 pool 문 앞에 다음 라인을 추가하고 변경 사항을 저장합니다.

     

    server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4
  3. chrony 서비스를 다시 시작합니다.

     

    ubuntu:~$ sudo /etc/init.d/chrony restart[ ok ] Restarting chrony (via systemctl): chrony.service.
  4. chrony가 169.254.169.123 IP 주소를 사용하여 시간을 동기화하고 있는지 확인합니다.

     

    ubuntu:~$ chronyc sources -v210 Number of sources = 7 .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current synced, '+' = combined , '-' = not combined, | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable. || .- xxxx [ yyyy ] +/- zzzz || Reachability register (octal) -. | xxxx = adjusted offset, || Log2(Polling interval) --. | | yyyy = measured offset, || \ | | zzzz = estimated error. || | | \ MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* 169.254.169.123 3 6 17 12 +15us[ +57us] +/- 320us ^- tbag.heanet.ie 1 6 17 13 -3488us[-3446us] +/- 1779us ^- ec2-12-34-231-12.eu-west- 2 6 17 13 +893us[ +935us] +/- 7710us ^? 2a05:d018:c43:e312:ce77:6 0 6 0 10y +0ns[ +0ns] +/- 0ns ^? 2a05:d018:d34:9000:d8c6:5 0 6 0 10y +0ns[ +0ns] +/- 0ns ^? tshirt.heanet.ie 0 6 0 10y +0ns[ +0ns] +/- 0ns ^? bray.walcz.net 0 6 0 10y +0ns[ +0ns] +/- 0ns

    반환된 출력에서 ^*는 기본 설정된 타임 소스를 나타냅니다.

  5. chrony에서 보고된 시간 동기화 지표를 확인합니다.

     

    ubuntu:~$ chronyc trackingReference ID : 169.254.169.123 (169.254.169.123) Stratum : 4 Ref time (UTC) : Wed Nov 29 07:41:57 2017 System time : 0.000000011 seconds slow of NTP time Last offset : +0.000041659 seconds RMS offset : 0.000041659 seconds Frequency : 10.141 ppm slow Residual freq : +7.557 ppm Skew : 2.329 ppm Root delay : 0.000544 seconds Root dispersion : 0.000631 seconds Update interval : 2.0 seconds Leap status : Normal

 

:

[AWS] ..user is not authorized to perform: iam:PassRole on resource.. 에러 시

Cloud&Container/AWS 2020. 3. 4. 18:35

항상 그렇지만 에러 메시지를 보면 답이 다 나와 있습니다.

"iam:PassRole" 에 대한 권한이 없다는 것입니다.

 

근데 충분한 권한을 줬다고 생각 했어도 왜 저런 에러가 나는 거지 하고 의심이 될 때가 있습니다.

원인도 찾았고 해결책도 찾았지만 AWS 뿐만 아니라 Cloud 서비스를 잘 사용하기 위해서는 보안과 권한에 대해서 정말 자세히 알고 고민을 하지 않으면 안될 것 같다는 확신이 또 들었습니다.

 

근데 생각 보다 IAM 관련해서 서비스 유형에 따른 템플릿 같은게 많이 없는 것 같아 좀 아쉽 더군요.

시간 날 때 한번 만들어 봐야 겠습니다.

 

iam:PassRole을 수행하도록 인증되지 않음

서비스 연결 역할을 생성하는 경우 해당 역할을 서비스에 전달할 권한이 있어야 합니다. 일부 서
비스는 서비스에서 작업을 수행할 때 계정에 서비스 연결 역할을 자동으로 생성합니다. 예를 들어
Amazon EC2 Auto Scaling에서는 사용자가 Auto Scaling 그룹을 처음으로 생성할 때 사용자를 대신해
AWSServiceRoleForAutoScaling 서비스 연결 역할을 생성합니다. PassRole 권한 없이 Auto Scaling
그룹을 생성하려고 하면 다음 오류가 발생합니다.

 

ClientError: An error occurred (AccessDenied) when calling the
PutLifecycleHook operation: User: arn:aws:sts::111122223333:assumed-role/
Testrole/Diego is not authorized to perform: iam:PassRole on resource:
arn:aws:iam::111122223333:role/aws-service-role/autoscaling.amazonaws.com/
AWSServiceRoleForAutoScaling

 

이 오류를 해결하려면 관리자에게 iam:PassRole 권한을 추가해 달라고 요청합니다.
서비스 연결 역할을 지원하는 서비스를 알아보려면 IAM로 작업하는 AWS 서비스 (p. 571) 단원을 참조하
십시오. 서비스가 자동으로 서비스 연결 역할을 생성하는지 여부를 알아보려면 예 링크를 선택하여 해당 서
비스의 서비스 연결 역할 설명서 단원을 참조하십시오.

 

저 역시 role 에서 정책을 하나 새로 만들어서 해결 했습니다.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "iam:GetRole",
                "iam:PassRole"
            ],
            "Resource": "arn:aws:s3:::test-iot-s3-action"
        }
    ]
}

Action 목록이 궁금 하신 분들은 아래 문서 참고 하세요.

https://docs.aws.amazon.com/IAM/latest/UserGuide/list_identityandaccessmanagement.html

:

[AWS IoT] CA 인증서 등록

Cloud&Container/AWS 2020. 3. 3. 20:42

참고 문서)

https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-your-own.html

 

$ openssl genrsa -out rootCA.key 2048
$ openssl req -x509 -new -extensions v3_ca -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
Country Name (KR) []:KR
State or Province Name (full name) []:
Locality Name (eg, city) []:
Organization Name (eg, company) []:
Organizational Unit Name (eg, section) []:
Common Name (eg, fully qualified host name) []:
Email Address []:
$ openssl genrsa -out verificationCert.key 2048
$ aws iot get-registration-code 
{
    "registrationCode": "879216d3f0b9fee2e0947fe32fd4ed9670d65fa9aff3e67e590582db30f62878"
}
$ openssl req -new -key verificationCert.key -out verificationCert.csr
Country Name (KR) []:KR
State or Province Name (full name) []:
Locality Name (eg, city) []:
Organization Name (eg, company) []:
Organizational Unit Name (eg, section) []:
Common Name (eg, fully qualified host name) []:879216d3f0b9fee2e0947fe32fd4ed9670d65fa9aff3e67e590582db30f62878
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
$ openssl x509 -req -in verificationCert.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out verificationCert.pem -days 500 -sha256
$ aws iot register-ca-certificate --ca-certificate file://rootCA.pem --verification-cert file://verificationCert.pem
{
    "certificateArn": "arn:aws:iot:ap-northeast-2:99999999999:cacert/879216d3f0b9fee2e0947fe32fd4ed9670d65fa9aff3e67e590582db30f62878",
    "certificateId": "879216d3f0b9fee2e0947fe32fd4ed9670d65fa9aff3e67e590582db30f62878"
}
 
$ cat /etc/ssl/openssl.cnf
[ req ]
#default_bits = 2048
#default_md = sha256
#default_keyfile  = privkey.pem
distinguished_name = req_distinguished_name
extensions               = v3_ca # 추가 설정
req_extensions           = v3_ca # 추가 설정
attributes = req_attributes

[ v3_ca ]
basicConstraints         = CA:TRUE # 추가 설정

[ req_distinguished_name ]
countryName = Country Name (KR)
countryName_min = 2
countryName_max = 2
stateOrProvinceName = State or Province Name (full name)
localityName = Locality Name (eg, city)
0.organizationName = Organization Name (eg, company)
organizationalUnitName = Organizational Unit Name (eg, section)
commonName = Common Name (eg, fully qualified host name)
commonName_max = 64
emailAddress = Email Address
emailAddress_max = 64

[ req_attributes ]
challengePassword = A challenge password
challengePassword_min = 4
challengePassword_max = 20

 

위 테스트는 맥북에서 진행 된 것입니다.

Ubuntu 에서는 별도 설정 변경 없이 잘 되는 것으로 이야기 들었습니다.

저 위에 빨간색 부분이 달라 계속 오류가 발생을 했었습니다.

 

[에러메시지]

An error occurred (CertificateValidationException) when calling the RegisterCACertificate operation: CA certificate is not valid.

The CA certificate does not have the basicConstraints extension as true

:

[AWS] ssh tunneling on ec2

ITWeb/개발일반 2020. 2. 26. 08:33

AWS Linux 로 EC2 생성을 했을 경우)

$ ssh -i key.pem ec2-user@hostname

 

AWS  Ubuntu 로 EC2 생성을 했을 경우)

$ ssh -i key.pem ubuntu@hostname

:

[AWS] VPC 부터 EC2 생성해서 SSH 연결해보기

Cloud&Container/AWS 2020. 2. 25. 16:30

AWS 에서 쵝 인프라 및 네트워크를 구성 하고 Bastion 설정을 통해 SSH Tunneling 을 해보도록 하겠습니다.

(기억력을 돕기 위해 작성한 내용입니다.)

 

[AWS에서 초기 인프라 및 네트워크 구성 하기]
생성 하는 순서는 아래와 같이 진행을 하시면 됩니다.

1. VPC 생성을 합니다.
2. Subnet 생성을 합니다.
- Public Subnet
- Private Subnet
3. Route Table 생성을 합니다.
- Public Route Table
- Private Route Table
4. Subnet 과 Route Table 연결을 합니다.
5. Internet Gateway 생성을 합니다.
- 인터넷 전용 연결 게이트웨이로 사용 합니다.
6. VPC 와 Internet Gateway 연결을 합니다.
7. Route Table 에서 Internet Gateway 연결을 합니다.
- Public Route Table 을 연결 합니다.
8. Network ACL 과 Security Group 설정을 합니다.
- 생성한 자원들에 대한 접근 제어 설계를 통해 구성 합니다.
- Inbounds, Outbounds


[VPC 생성]
- 생성할 VPC Name tag 를 작성 합니다.
- vpc-startup
- IPv4 CIDR block 을 작성 합니다.
- 10.0.0.0/16
참고 글)
https://jjeong.tistory.com/1405
- IPv6 CIDR block 은 기본 "No IPv6 CIDR Block" 을 선택 합니다.
- Tenancy 는 "Default" 를 선택 합니다.

[Subnet 생성]
- 생성할 Subnet 의 Name tag 를 작성 합니다.
- sbn2a-prd-public
- sbn2b-prd-private
- 연결할 VPC 를 선택 합니다.
- 생성할 Availability Zone 을 선택 합니다.
- VPC CIDR 범위에 속하는 IPv4 CIDR block 을 등록 합니다.
- 10.0.0.0/20
- First IP : 10.0.0.0
- Last IP : 10.0.15.255
- AWS 내 Available IPv4 Addresses : 4091 개

[Route Table 생성]
- 생성할 Route Table 의 Name tag 를 작성 합니다.
- rtb-prd-public
- rtb-prd-private
- 연결할 VPC 를 선택 합니다.

[Subnet 과 Route Table 연결]
- Route Table 정보 화면에서 Subnet Associations 를 선택 합니다.
- Edit subnet associations 를 클릭 합니다.
- 연결할 Subnet 을 선택 합니다.

[Internet Gateway 생성 / VPC 와 연결]
- 생성할 Internet Gateway 의 Name tag 를 작성 합니다.
- 목록에서 생성한 IGW 를 선택 하고 Actions 에서 Attach to VPC 를 통해 연결 합니다.

[Route Table 에 Internet Gateway 연결]
- Public Route Table 에서 Routes 탭의 Edit routes 를 클릭 합니다.
- Add route 를 통해 IGW 를 등록 합니다.
- 0.0.0.0/0

[Network ACL 설정 및 Subnet 연결]
- Public zone 과 Private zone 에 대한 ACL 을 생성 합니다.
- 생성할 ACL 의 Name tag 를 작성 합니다.
- acl-prd-public
- acl-prd-private
- 연결할 VPC 를 선택 합니다.
- Public zone acl 에 SSH Tunnel Gateway 구성을 위한 Inbound Rule 을 생성 합니다.
- 초기 SSH 연결 테스트만 하기 위한 설정 입니다.
- SSH(22), TCP(6), 22, 0.0.0.0/0, ALLOW
- Private zone acl 에 Inbound Rule 을 생성 합니다.
- SSH Tunnel Gateway 에서 접속 할 수 있도록 SSH 오픈 및 Source 제한을 합니다.
- 설정한 ACL 을 Subnet 에 적용 될 수 있도록 연결 설정 합니다.

[Security Group 생성]
- 생성할 Security Group Name 을 작성 합니다.
- 사용할 VPC 를 선택 합니다.
- SSH Tunnel Gateway 구성을 위한 Inbound 를 설정 합니다.
-  SSH, TCP, 22, My IP 로 Add Rule 합니다.
- Outbound 는 All 로 구성 합니다.

여기까지 했으면 VPC, ZONE, Security 에 대한 기본 구성을 해본 것입니다.
이제 EC2 인스턴스를 생성해서 SSH Tunnel 용 Gateway (Bastion) 를 구성해 보도록 하겠습니다. 

[EC2 생성]
- Amazon Linux 2 AMI 를 선택 합니다.
t2.micro 를 선택 합니다. (저는 free tier 적용을 위해 선택 했기 때문에 용도와 목적에 맞게 선택 하시면 됩니다.)
- 생성할 VPC 를 선택 합니다.
- 생성할 Subnet 을 선택 합니다.
- Public IP 할당 여부를 선택 합니다. (Bastion 구성을 위해 Public IP 할당)
- Storage, Tag 설정 이후 Security Group 설정을 합니다.
- Select an existing security group 을 통해 이미 만들어 놓은 것을 선택 합니다.
- Key pair 를 다운받습니다.
- 인스턴스를 시작 합니다.

[SSH 연결]
$ ssh -i ec2key-prd-gw.pem ec2-user@ec2-xxx-xxx-xxx-xxx.ap-northeast-2.compute.amazonaws.com

[ssh-keygen on 맥북]
$ ssh-keygen -t rsa
$ cat .ssh/id_rsa.pub
ssh-rsa .....HENRYJEONG.local

[User 생성]

https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/managing-users.html
[ec2-user@ip-42 ~]$ sudo adduser henryjeong
[ec2-user@ip-42 ~]$ sudo su - henryjeong
[henryjeong@ip-42 ~]$ mkdir .ssh
[henryjeong@ip-42 ~]$ chmod 700 .ssh
[henryjeong@ip-42 .ssh]$ touch authorized_keys
[henryjeong@ip-42 .ssh]$ chmod 600 authorized_keys
[henryjeong@ip-42 .ssh]$ vi authorized_keys

[User 로 접속]
$ ssh henryjeong@xxx.xxx.xxx.xxx
Last login: Tue Feb 25 07:23:45 2020

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
[henryjeong@ip-10-0-6-44 ~]$

# EC2 에 Public IP 는 생성이 되었으나 Public DNS 가 생성되지 않았을 경우 

Your answer

  • Go to console.aws.amazon.com.
  • Go To Services and then VPC.
  • Open Your VPCs.
  • Select your VPC connected to your EC2 and.
  • Choose Select Actions.
  • Click on Edit DNS Hostnames.
  • Then Change DNS hostnames: to YES.
:

[Logstash] AWS SQS + Logstash 구성

Elastic/Logstash 2018. 8. 28. 09:52

가끔 사용하다가도 처음 사용할  때 이해했던 내용과 다르게 기억 될 때가 있습니다.

그래서 또 복습 합니다.


구성은 아래와 같습니다.


File Log --> Logstash Agent --> SQS -->

Logstash Collector --> 

File

Elasticsearch

Logstash Collector --> 

File

Elasticsearch


각 서버의 file log 를 input file 로 읽고 output sqs 로 보냅니다.

그런 후 input sqs 를 읽고 multi output 으로 file 과 elasticsearch 로 저장을 하게 되는 구조 입니다.


여기서 AWS 의 SQS 에 대한 메시지 수명 주기에 대한 이해가 필요 합니다.


원문)

https://aws.amazon.com/ko/sqs/details/


Amazon SQS 메시지 수명 주기

Amazon SQS에 저장된 메시지에는 관리가 쉬우면서도 모든 메시지가 처리되도록 보장하는 수명 주기가 있습니다.


1. 메시지를 보내야 하는 시스템에서는 Amazon SQS 대기열을 선택하고 SendMessage를 사용하여 새 메시지를 전송합니다.

2. 메시지를 처리하는 다른 시스템은 처리할 메시지가 더 많이 필요해지므로 ReceiveMessage를 호출하고, 해당 메시지가 반환됩니다.

3. ReceiveMessage에 의해 메시지가 반환되면 해당 메시지는 제한 시간이 초과할 때까지는 다른 어떤 ReceiveMessage에 의해서도 반환되지 않습니다. 이는 다수의 소비자가 동일한 메시지를 동시에 처리하는 것을 방지합니다.

4. 메시지를 처리하는 시스템에서 메시지 작업을 성공적으로 완료하면, 해당 시스템에서는 다른 시스템에서 해당 메시지를 다시 처리하지 않도록 DeleteMessage를 호출하여 메시지를 대기열에서 제거합니다. 시스템에서 메시지 처리에 실패하는 경우, 제한 시간이 초과하는 즉시 다른 ReceiveMessage 호출을 통해 해당 메시지를 읽습니다.

5. 소스 대기열에 배달 못한 편지 대기열이 연결되어 있는 경우 지정한 최대 배달 시도 횟수에 도달한 이후에는 메시지가 배달 못한 편지 대기열로 이동됩니다.


결국 정리 하면, consumer 가 읽어 가면 다른 consumer 는 이미 읽어간 데이터를 읽어 가지 못합니다. 이유는 위 설명에서와 같이 삭제 되기 때문 입니다.

단일 큐를 사용하면서 큐에 쌓인 메시지의 소비는 다중 consumer 로 처리 하고 단일 저장소로 저장 할 경우 쉽게 구성 할 수 있다는 이야기 였습니다.


여기서 제가 착각한 포인트는 읽어간 메시지가 삭제 되지 않는다는 것이였구요.

이런 오해는 "메시지는 최대 14일 동안 대기열에 보관됩니다." 라는 걸 보고 착각한 것이였습니다.


:

[AWS] ELB + http to https + Nginx 설정

ITWeb/개발일반 2017. 2. 2. 10:12

요즘 대부분의 서비스들이 http 를 제거 하고 https 로 서비스 하기 시작했습니다.

AWS 에서 제공하는 SSL 을 이용해서 ELB 에 구성하신 분들의 경우 대부분 아래와 같이 되어 있을 것 같은데요.


http://service    -> elb:80   -> ec2:80

https://service  -> elb:443  -> ec2:80


이와 같이 되어 있다 보니 개별 ec2 에서는 모두 listen 80 만 하게 됩니다.

그래서 client 에서 http 로 들어 왔는지 https 로 들어 왔는지 확인이 필요 한데요.

이 경우 아래와 같은 변수들을 활용해서 설정을 하시면 됩니다.


[참고문서]

http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/x-forwarded-headers.html


[X-Forwarded Headers]

X-Forwarded-For

X-Forwarded-Proto

X-Forwarded-Port


[Nginx 설정]

server {

  listen       80;

  server_name  localhost;


  if ($http_x_forwarded_proto = 'http') {

    return 301 https://$server_name$request_uri;

  }

}


참고 용이니 실 서비스에 적용 시 충분한 테스트 후 적용하시기 바랍니다.

:

[AWS] Instance register/deregister on AWS ELB

ITWeb/개발일반 2016. 6. 24. 18:19

AWS에서 ELB 사용 시 instance 를 넣고 빼고 하는 CLI 예제 입니다.

제가 필요해서 그냥 기록해 봅니다.


[참조문서]

http://docs.aws.amazon.com/cli/latest/reference/elb/index.html



[AWS CLI 구성]

https://aws.amazon.com/ko/cli/



[AWS Configure]

이 작업은 aws cli를 사용하기 위한 access key 와 secret access key 그리고 region 등록을 하게 됩니다.

설정을 완료 하게 되면 user home 아래 .aws/config 파일이 생성 됩니다.


# .awc/config
[default]
region = ap-northeast-1
aws_secret_access_key = xxxxxxxxx
aws_access_key_id = xxxxxxxx
output = json


- 여기서 주의 하실 점은 region 정보에 tokyo 에 있다고 tokyo 로 하시면 못찾습니다. 위 예시와 같이 작성해 주셔야 합니다.




[AWS ELB 등록 정보]

$ aws elb describe-load-balancers --load-balancer-name kr-search-memebox-com



[AWS ELB 인스턴스 등록]

$ aws elb register-instances-with-load-balancer
 --load-balancer-name
 ELB명 --instances INSTANCE명



[AWS ELB 인스턴스 제거]

$ aws elb deregister-instances-from-load-balancer

 --load-balancer-name ELB명 --instances INSTANCE명


:

[AWS] JVM 타임존 설정 이슈

ITWeb/개발일반 2016. 6. 7. 14:52

aws 에서 인스턴스 생성 후 java program 에서 사용하던 Date 클래스에서의 시간이 잘 못 나오는 경우가 발생했습니다.

shell 에서 $ date 하면 정상적으로 KST 기준으로 시간이 잘 표시되지만 java application 에서는 GMT 0 로 시간이 표시 되는 문제 입니다.


해결 방법은 크게 두 가지 입니다.


1) 소스 코드에서 timezone 지정을 해서 date 설정을 하는 것입니다.

TimeZone timeZone;

Date date = new Date();

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM.dd HH:mm");


timeZone = TimeZone.getTimeZone("Asia/Seoul");

simpleDateFormat.setTimeZone(timeZone);


LOG.debug("{}", simpleDateFormat.format(date));


2) 서버 인스턴스 상에서 timezone 설정을 다시 하는 것입니다.

$ sudo tzselect


5) Asia

...

23) Korea (South)

...

1) Yes

...


$ vi .profile

 

TZ='Asia/Seoul'

export TZ


- 우분투로 구성 하였기 때문에 timezone 구성은 위와 같이 진행 하였습니다.

: