安装
先决条件
- 您将需要Port credentials 来安装 AWS 输出程序:
Get your Port credentials
To get your Port API credentials go to your Port application, click on the
...button in the top right corner, and selectCredentials. Here you can view and copy yourCLIENT_IDandCLIENT_SECRET: - AWS CLI 是身份验证所必需的。确保已设置 AWS
Access key id和Secret access key。如果没有,请在终端运行aws configure进行配置。
对于step-by-step installation (未被用于 Terraform) ,也要安装:
Terraform 安装(推荐)
在终端运行以下脚本
# Export your Port credentials
export PORT_CLIENT_ID=YOUR-PORT-CLIENT-ID
export PORT_CLIENT_SECRET=YOUR-PORT-CLIENT-SECRET
# Clone the terraform template
git clone https://github.com/port-labs/template-assets.git
cd template-assets/aws
# Initialize the Terraform requirements
terraform init
# Deploy the aws exporter and provide the resources you want to export
terraform apply -var 'resources=["ecs_service", "lambda", "sns", "sqs", "s3_bucket", "rds_db_instance", "dynamodb_table", "ec2_instance"]'
- 在 Port 环境中创建资源蓝图。
- 在 AWS 环境中使用以下资源部署 AWS 输出程序 -S3 bucket,mapping configuration file,AWS secret,AWS IAM policy ;
- 设置Event Bridge Rules ,触发出口程序更新资源;
- 首次调用 AWS 输出程序 Lambda 函数以获取当前资源状态。
AWS 出口商 Terraform 模块
设置基本配置后,上述模板将部 署 AWS 出口商 Terraform 模块。
欲了解更多信息,请访问AWS exporter module docs
分步安装
此处概述的步骤可用于使用 CloudFormation 手动安装 AWS 输出程序。
要部署应用程序,您需要填写以下参数:
- **云形成相关参数: **
- 应用程序名称"- 通过 "AWS CloudFormation "创建的应用程序的堆栈名称。
- **桶相关参数: **
CreateBucket- 如果希望应用程序创建和管理您的存储桶,则为true;如果希望自行创建存储桶,则为false。BucketName- 你的邮筒的名称,或一个新邮筒的全局唯一名称。ConfigJsonFileKey- 文件桶中config.json的文件密钥(路径)。
- ** IAM 策略相关参数: **
CustomIAMPolicyARN-IAM policy 的 ARN。
- **与 secret 相关的参数: **
CustomPortCredentialsSecretARN- Port凭据secret的 ARN; **或SecretName- 要创建的新Port凭据secret的名称。
- **与 Lambda 相关的参数: **
FunctionName- 输出程序 lambda 的函数名。ScheduleExpression-schedule expression ,用于定义出口程序的事件日程。ScheduleState- 计划表的初始状态 -ENABLED或DISABLED。建议仅在成功运行一次后启用。
- 准备一个
config.json文件,该文件将定义将哪些 AWS 资源摄取到 Port; - 创建
IAM policy,为config.json中的 AWS 资源提供list和read权限;
-
Deploy our
serverless application.- AWS Console
- AWS CLI
You can deploy the application from the AWS console through this link.
Follow these steps:
-
Create a
parameters.jsonfile to override certain parameters values. For example (replace the placeholders):[
{
"Name": "CustomIAMPolicyARN",
"Value": "<YOUR_IAM_POLICY_ARN>"
},
{
"Name": "CustomPortCredentialsSecretARN",
"Value": "<YOUR_PORT_CREDENTIALS_SECRET_ARN>"
},
{
"Name": "CreateBucket",
"Value": "false"
},
{
"Name": "BucketName",
"Value": "<YOUR_BUCKET_NAME>"
},
{
"Name": "ScheduleExpression",
"Value": "rate(1 hour)"
},
{
"Name": "ScheduleState",
"Value": "DISABLED"
}
] -
Use the following command to create a change set:
aws serverlessrepo create-cloud-formation-change-set --application-id arn:aws:serverlessrepo:eu-west-1:185657066287:applications/port-aws-exporter --stack-name port-aws-exporter --capabilities CAPABILITY_IAM CAPABILITY_RESOURCE_POLICY --parameter-overrides file://parameters.json
# Result
{
"ApplicationId": "arn:aws:serverlessrepo:eu-west-1:185657066287:applications/port-aws-exporter",
"ChangeSetId": "<ChangeSetId>",
...
} -
With the
<ChangeSetId>from the previous command output, deploy the change set:aws cloudformation execute-change-set --change-set-name "<ChangeSetId>"
部署完成后,请使用以下 AWS SAM CLI 命令来获取出口程序资源的有用列表:
sam list stack-outputs --stack-name serverlessrepo-port-aws-exporter
名单包括
- Lambda 函数 ARN` - 输出端 Lambda 的 ARN;
- Port凭据secret ARN` - Port凭据secret的 ARN;
ConfigBucketName- 输出者的存储桶名称。
有关如何部署无服务器应用程序的详细信息,请单击here 。
- 使用您的证书更新
Port credentials secret;
- 将
config.json上传到出口程序的 S3 存储桶。
测试应用程序
为了测试已部署的应用程序,应使用空测试事件 ({}) 运行出口程序的 lambda,并查看执行状态和日志。
故障排除
查看日志
要在一个地方查看所有 lambda 实例的日志,可以使用Cloudwatch Logs 或AWS SAM Logs :
sam logs --stack-name serverlessrepo-port-aws-exporter --tail