5 مورد برتر استفاده ChatGPT در نقش AWS Solution Architecture

خوش آمدی
سلام، دوستان من! امروز میخواهم 5 مورد برتر استفاده از ChatGPT در کار روزانهام را با شما به اشتراک بگذارم. اما قبل از شیرجه رفتن، اجازه دهید یک داستان کوچک برای شما تعریف کنم. اخیراً برای یادداشت برداری از Obsidian به Logseq تغییر مکان دادم و به طور کلی عادت به ترجیح فرم های کوتاه تر را پیدا کردم. بنابراین، بیایید مستقیماً به اصل مطلب برویم و بررسی کنیم که چگونه ChatGPT میتواند به ما در صرفهجویی در زمان و آسانتر کردن زندگیمان کمک کند!
ابزارهای مورد استفاده در این قسمت
قبل از شروع، اجازه دهید به سرعت ابزارهایی را که برای این موارد استفاده خواهیم کرد مرور کنیم:
- AWS CLI: رابط خط فرمان برای تعامل با خدمات AWS
- ChatGPT: دستیار قابل اعتماد هوش مصنوعی ما
- CloudFormation: زیرساخت AWS بومی به عنوان ابزار کد
- ZSH: یک پوسته قدرتمند با ویژگی های جالب
حالا بیایید به دنیای هیجان انگیز ChatGPT بپریم!
استفاده از مورد 1: دریافت زیرشبکه ها
تصور کنید که شما مسئول نوشتن برخی اسناد واگذاری منطقه فرود هستید. شما باید زیرشبکه های متعددی را در چندین حساب AWS فهرست کنید. می تواند بسیار خسته کننده و وقت گیر باشد. اما نترس! ChatGPT اینجاست تا روز را نجات دهد.
برای ایجاد یک جدول Markdown که تمام زیرشبکهها را در یک VPC خاص فهرست میکند، از دستور زیر استفاده کنید:
List in the form of a Markdown table all the subnets in VPC ID x.
Display the Subnet ID, CIDR Block, and the tag 'Name' in a
column named 'Name'. Use the AWS CLI.
Format the tags as a string, not an array.
که تولید می کنند:
aws ec2 describe-subnets \
--filters "Name=vpc-id,Values=x" \
--query 'Subnets[*].{SubnetId: SubnetId, CidrBlock: CidrBlock, Tags: Tags[?Key==`Name`].Value | [0]}' \
--output text | awk 'BEGIN{print "| Subnet ID | CIDR Block | Name |"} {printf("| %-12s | %-11s | %-4s |\n", $1, $2, $3)}'
نتیجه؟ تا-دا! جدولی با فرمت منظم با تمام جزئیات لازم.
شناسه زیر شبکه | بلوک CIDR | نام |
---|---|---|
subnet-0a703b1877c7d6b3a | 10.201.10.0/26 | |
subnet-Application-1-primary-vpc | ||
زیر شبکه-0e8f05f1b6c45ec51 | 10.201.10.192/26 | |
subnet-Data-2-primary-vpc | ||
subnet-0fd362daf67578490 | 10.201.10.128/26 | |
subnet-Data-1-primary-vpc | ||
subnet-0ef10e7b79ad98de5 | 10.201.10.64/26 | |
subnet-Application-2-primary-vpc | ||
subnet-0d931e05c320692eb | 10.201.8.0/24 | |
subnet-Public-1-primary-vpc | ||
subnet-06144454dbd44ed21 | 10.201.9.0/24 | |
subnet-Public-2-primary-vpc |
استفاده از مورد 2: اتصال به نمونه های در حال اجرا
آیا ترجیح می دهید از AWS Systems Manager (SSM) به جای SSH برای دسترسی به نمونه ها استفاده کنید؟ اگر چنین است، در اینجا یک نام مستعار مفید برای شما وجود دارد:
alias ssm="aws ssm start-session --target"
اما برای استفاده از این نام مستعار، به لیستی از نمونه های در حال اجرا EC2 با شناسه آنها نیاز دارید. ChatGPT یک بار دیگر پشت شماست!
برای ایجاد جدول Markdown که تمام نمونههای EC2 در حال اجرا را به همراه شناسههای نمونه، وضعیت و برچسبهای آنها (env و project) فهرست میکند، از دستور زیر استفاده کنید:
List all running EC2 instances, get instanceid,
status, and tags: env, project.
Based on that build markdown table, which will display
following columns id, status, env, project and fill
it with gathered data. Get tags as string, not array
خروجی تولید شده عبارت بود از:
aws ec2 describe-instances \
--filters "Name=instance-state-name,Values=running" \
--query 'Reservations[].Instances[].[InstanceId, State.Name, join(`,`,Tags[?Key==`env`].Value), join(`,`,Tags[?Key==`project`].Value)]' \
--output text | awk -F'\t' '{print "| " $1 " | " $2 " | " $3 " | " $4 " |"}'
وویلا! اکنون جدولی دارید که اطلاعات ضروری در مورد نمونه های در حال اجرا شما را نشان می دهد.
| i-0f9c122fccddaf11f | running | dev | sectree |
| i-0f9c1991ddde81fff | running | dev | sectree |
| i-00dd122f3ade91dds | running | dev | sectree |
این راه حل به عنوان یک منهای، ساختن نام مستعار zsh با آن سخت است. با این حال میتوانیم از fzf در اینجا استفاده کنیم و آن را کمی آسانتر کنیم.
استفاده از مورد 3: مستندات
گاهی اوقات، ما نیاز به نوشتن اسناد برای اهداف داخلی داریم، به خصوص وقتی صحبت از ماژولهای مشابه S3 میشود. ChatGPT می تواند کمک فوق العاده ای در چنین شرایطی باشد!
برای ایجاد اسناد به سبک README در مورد استفاده اولیه از دستور AWS CLI S3، به سادگی از ChatGPT بپرسید:
Generate readme style documentation
about basic usage of aws cli s3 command. Print is as markdown
و درست مانند جادو، شما یک راهنمای جامع در دستان خود خواهید داشت که نصب، پیکربندی و استفاده اولیه از دستور AWS CLI S3 را پوشش می دهد. که به نظر می رسد:
# AWS CLI S3 Command - README
This document provides an overview of the basic usage of the AWS Command Line Interface (CLI) S3 command. The AWS CLI allows you to interact with Amazon Simple Storage Service (S3), a highly scalable cloud storage service provided by Amazon Web Services (AWS).
## Installation
To use the AWS CLI, you need to have it installed on your local machine. Follow these steps to install the AWS CLI:
1. Ensure that you have Python 3 installed on your machine. You can check this by running the command `python3 --version` in your terminal.
2. Install the AWS CLI by running the following command in your terminal:
`pip3 install awscli`
3. Once the installation is complete, you can verify it by running the command `aws --version`. It should display the version of the AWS CLI installed.
## Configuration
Before using the AWS CLI S3 command, you need to configure it with your AWS credentials. Follow these steps to configure the AWS CLI:
1. Obtain your AWS access key ID and secret access key from the AWS Management Console.
2. Run the following command in your terminal:
`aws configure`
3. When prompted, enter your AWS access key ID, secret access key, default region name, and default output format. The default region name is the AWS region where you want to perform your S3 operations (e.g., `us-east-1`).
4. Once the configuration is complete, the AWS CLI is ready to use.
## Basic Usage
The AWS CLI S3 command provides a set of subcommands to interact with S3 buckets and objects. Here are some common examples of how to use the AWS CLI S3 command:
### 1. List Buckets
To list all the S3 buckets in your AWS account, use the following command:
`aws s3 ls`
### 2. List Objects in a Bucket
To list all the objects in a specific S3 bucket, use the following command:
`aws s3 ls s3://bucket-name`
Replace `bucket-name` with the name of the bucket you want to list objects from.
### 3. Upload a File to a Bucket
To upload a file to an S3 bucket, use the following command:
`aws s3 cp /path/to/local/file s3://bucket-name/key`
Replace `/path/to/local/file` with the local file path you want to upload, `bucket-name` with the name of the target bucket, and `key` with the desired key/name for the uploaded file in S3.
### 4. Download a File from a Bucket
To download a file from an S3 bucket to your local machine, use the following command:
`aws s3 cp s3://bucket-name/key /path/to/local/file`
Replace `bucket-name` with the name of the source bucket, `key` with the key/name of the file in S3, and `/path/to/local/file` with the local file path where you want to save the downloaded file.
### 5. Delete a File from a Bucket
To delete a file from an S3 bucket, use the following command:
`aws s3 rm s3://bucket-name/key`
Replace `bucket-name` with the name of the bucket containing the file to delete, and `key` with the key/name of the file in S3.
## Additional Resources
For more information on the AWS CLI S3 command and its options, you can refer to the official AWS CLI documentation:
- [AWS CLI S3 Command Reference](https://docs.aws.amazon.com/cli/latest/reference/s3/index.html)
استفاده از مورد 4: بهبود امنیت
آیا به دنبال بهبود امنیت و کیفیت قالب های AWS CloudFormation خود هستید؟ جلوترش رو نگاه نکن! ChatGPT می تواند چند پیشنهاد روشنگر به شما ارائه دهد.
فرض کنید یک الگوی CloudFormation برای یک گروه امنیتی EC2 دارید که میتواند از سختسازی استفاده کند. از ChatGPT بخواهید امنیت و کیفیت آن را بهبود بخشد و الگو را به عنوان ورودی ارائه کند. شما یک نسخه پیشرفته دریافت خواهید کرد که بهترین شیوه های امنیتی را در اولویت قرار می دهد. با اعلان مانند این:
Improve security and quality of fallowing AWS CloudFormation template:
Resources:
MySecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: My Security Group
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
- IpProtocol: -1
SecurityGroupEgress:
- CidrIp: 0.0.0.0/0
- IpProtocol: -1
نتیجه ما این خواهد بود:
Resources:
WebServerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security Group for Web Server
SecurityGroupIngress:
- CidrIp: 10.0.0.0/24
- IpProtocol: tcp
- FromPort: 22
- ToPort: 22
SecurityGroupEgress:
- CidrIp: 0.0.0.0/0
- IpProtocol: tcp
- FromPort: 80
- ToPort: 443
استفاده از مورد 5: آزمایش منطقه فرود
آیا تا به حال خود را نیاز به آزمایش یک محیط خاص یافته اید؟ این یک گام مهم در بررسی های پس از اجرا است. اما نترسید، هموطنان ماجراجو، زیرا من قدرت ChatGPT را برای شما به ارمغان میآورم، دستیار هوش مصنوعی دوستانهای که همیشه اینجاست تا کمک کند!
این سناریو را تصور کنید: میخواهید یک الگوی AWS CloudFormation را بچرخانید که یک نمونه t2.micro در یک زیرشبکه عمومی، یک نمونه دیگر در یک زیرشبکه خصوصی، یک ALB (Application Load Balancer) ایجاد میکند و ALB را به نمونه در خصوصی متصل میکند. زیر شبکه پیچیده به نظر می رسد، درست است؟ اما با ChatGPT در کنار شما، این یک نسیم است!
در اینجا الگوی جادویی CloudFormation است که ChatGPT با استفاده از اعلان برای ما ساخته است:
Generate AWS Cloudformation template that will spin one t2.micro
instance in public subnet, second in private subnet,
add ALB and attach it to instance in private subnet.
Additionally: Treat subnets ids as parameters. Assume
that networking part is done, already Install nginx on
instance in private subnet Get ALB DNS as output variable,
and based on it generate curl command
پاسخ ChatGPT:
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
PublicSubnetId:
Type: String
Description: ID of the public subnet
PrivateSubnetId:
Type: String
Description: ID of the private subnet
Resources:
PublicInstance:
Type: "AWS::EC2::Instance"
Properties:
InstanceType: t2.micro
ImageId: ami-xxxxxxxx # Replace with your desired AMI ID
SubnetId: !Ref PublicSubnetId
PrivateInstance:
Type: "AWS::EC2::Instance"
Properties:
InstanceType: t2.micro
ImageId: ami-xxxxxxxx # Replace with your desired AMI ID
SubnetId: !Ref PrivateSubnetId
UserData:
Fn::Base64: !Sub |
#!/bin/bash
yum update -y
yum install -y nginx
service nginx start
chkconfig nginx on
LoadBalancer:
Type: "AWS::ElasticLoadBalancingV2::LoadBalancer"
Properties:
Name: MyLoadBalancer
Subnets:
- !Ref PublicSubnetId
SecurityGroups:
- !Ref LoadBalancerSecurityGroup
Type: application
TargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
Name: MyTargetGroup
Port: 80
Protocol: HTTP
TargetType: instance
Targets:
- Id: !Ref PrivateInstance
Port: 80
Listener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
LoadBalancerArn: !Ref LoadBalancer
Port: 80
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref TargetGroup
Outputs:
ALBDNS:
Value: !GetAtt LoadBalancer.DNSName
Description: DNS name of the Application Load Balancer
شگفت انگیز نیست؟ این الگو نمونه ها را تنظیم می کند، Nginx را روی نمونه خصوصی نصب می کند، ALB را ایجاد می کند و همه چیز را برای شما پیکربندی می کند. فقط شناسه های زیرشبکه را به عنوان پارامتر ارائه کنید، و شما آماده هستید!
اما صبر کنید، چیزهای بیشتری وجود دارد! ChatGPT حتی یک دستور curl مفید را برای شما ایجاد کرد تا ALB را آزمایش کنید. به سادگی پشته CloudFormation را مستقر کنید و سپس از نام ALB DNS در دستور زیر استفاده کنید:
$ ALB_DNS=$(aws cloudformation describe-stacks --stack-name <stack-name> --query 'Stacks[0].Outputs[?OutputKey==`ALBDNS`].OutputValue' --output text)
$ curl http://${ALB_DNS}
خلاصه
در این پست وبلاگ، این سوال را بررسی می کنیم که آیا باید از هوش مصنوعی، به ویژه هوش مصنوعی مولد، ترس داشته باشیم. به نظر من، نیازی به ترس نیست – حداقل هنوز. در عوض، من هوش مصنوعی، به ویژه ChatGPT را به عنوان یک دوست نیازمند می بینم تا یک دشمن. این پست این ایده را به چالش می کشد که هوش مصنوعی، مانند یک سیستم هوشمند Articician، می تواند به طور کامل جایگزین معماران، توسعه دهندگان و طراحان Solution شود. از طریق تجربیات شخصی، میخواهم بر اهمیت یادگیری نحوه برقراری ارتباط مؤثر با اعلانهای هوش مصنوعی و استفاده از آنها برای اهداف درست تأکید کنم. در نهایت، من معتقدم که هوش مصنوعی به عنوان دستیار ارزشمندی عمل میکند، که میتواند کارهای خستهکنندهای را که قبلاً برای انسانها بسیار گران یا وقتگیر بودند، انجام دهد.