linux trying import event target

葫芦的运维日志

下一篇 搜索 上一篇

浏览量 231

2021/02/20 00:45


问题:terraform import aws_cloudwatch_event_target时需要提供target-id,但是aws控制台并没有显示target-id?

Question:terraform import aws_cloudwatch_event_target need to provide target-id,but aws console does not show target-id?

解决:通过 aws cli命令显示

Solution:Display by aws command

 

下面是详细步骤

Here are the detailed steps

zi.wang@ziwangdeMacBook-Pro aws % aws events list-targets-by-rule --rule mycat-coupon-rule-offlineDistributionChannelTrigger-prod --region cn-north-1
{
    "Targets": [
        {
            "Id": "Id123456789",
            "Arn": "arn:aws-cn:sqs:cn-north-1:*****:demo-test-sqs-trigger-prod",
            "Input": "{ \"Message\": { \"type\": \"trigger\" } }"
        }
    ]
}

terraform import -var-file prod.aws.key aws_cloudwatch_event_target.trigger demo-test-sqs-trigger-prod/Id123456789

--var-file:中的key文件是通过请求获取临时token得到。

The key file in --var-file: is obtained by requesting a temporary token.

cat aws_prod.sh
#!/bin/bash
export AWS_ACCESS_KEY_ID="awsid" && export AWS_SECRET_ACCESS_KEY="awsSECRETkey" && \
aws sts assume-role --duration-seconds 21600  --role-arn arn:aws-cn:iam::123456:role/test-prod-developer \
--role-session-name test --serial-number arn:aws-cn:iam::123456:mfa/test \
--region cn-north-1 --token-code $1
bash aws_prod.sh mfanumber

获取AccessKeyId,SecretAccessKey,SessionToken 

Get AccessKeyId,SecretAccessKey,SessionToken

cat > prod.aws.key <<EOF
aws_access_key = "xxx"
aws_secret_key = "xxx"
aws_session_token = "xxx"
EOF

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2021 王梓打赏联系方式 陕ICP备17005322号