{
"source": ["aws.support"],
"detail-type": ["Support Case Update"],
"detail": {
"event-name": ["ResolveCase"]
}
}
{
"version": "0",
"id": "1aa4458d-556f-732e-ddc1-4a5b2fbd14a5",
"detail-type": "Support Case Update",
"source": "aws.support",
"account": "111122223333",
"time": "2022-02-21T15:51:31Z",
"region": "us-east-1",
"resources": [],
"detail": {
"case-id": "case-111122223333-muen-2022-7118885805350839",
"display-id": "1234563851",
"communication-id": "",
"event-name": "ResolveCase",
"origin": ""
}
}
def describe_case(case_id):
response = support.describe_cases(
caseIdList=[
case_id
],
includeResolvedCases=True,
includeCommunications=False
)
return response['cases'][0]
def lambda_handler(event, context):
case_info = describe_case(event['detail']['case-id'])
def lambda_handler(event, context):
case_info = describe_case(event['detail']['case-id'])
if case_info['serviceCode'] == "service-limit-increase" or \
case_info['subject'] == "Enterprise Activation Request for Linked account.":
return {
'Result': 'Service limit increase or Enterprise support activation will not be posted.'
}
def describe_communications(case_id):
body = ""
paginator = support.get_paginator('describe_communications')
page_iterator = paginator.paginate(caseId=case_id)
for page in page_iterator:
for communication in page['communications']:
body = re.sub(
r'-{3,}|={3,}|\*{3,}|_{3,}', "---", communication['body']
) + '\n\n---\n\n' + body
communications = '## Communications\n' + body
return communications
---------------------------------------------------
サポートからの回答や引用は破線などで区切られがち
ヘッダーや水平線として認識されないように置換しておく
---------------------------------------------------
---
サポートからの回答や引用は破線などで区切られがち
ヘッダーや水平線として認識されないように置換しておく
---
{
"body": "string",
"path": "/",
"grant": 1,
"grantUserGroupId": "5ae5fccfc5577b0004dbd8ab",
"pageTags": [
{
"_id": "5e2d6aede35da4004ef7e0b7",
"name": "daily",
"count": 3
}
],
"createFromPageTree": true
}
def create_payload(account_id, case_info):
token = os.environ['API_KEY']
title = '# ' + case_info['subject'] + '\n'
information = '## Case Information\n' + \
'* アカウント ID: ' + account_id + '\n' + \
'* ケース ID: ' + case_info['displayId'] + '\n' +\
'* 作成日: ' + case_info['timeCreated'] + '\n' + \
'* 重要度: ' + case_info['severityCode'] + '\n' + \
'* サービス: ' + case_info['serviceCode'] + '\n' + \
'* カテゴリ: ' + case_info['categoryCode'] + '\n'
communications = describe_communications(case_info['caseId'])
return {
'access_token': token,
'path': '/投稿したいパス/' + case_info['subject'],
'body': title + information + communications,
'grant': 1,
}
def lambda_handler(event, context):
case_info = describe_case(event['detail']['case-id'])
payload = create_payload(event['account'], case_info)
url = os.environ['API_URL']
headers = {
'Content-Type': 'application/json',
}
req = Request(url, json.dumps(payload).encode('utf-8'), headers)
from logging import getLogger, INFO
import json
import os
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
import re
from botocore.exceptions import ClientError
import boto3
logger = getLogger()
logger.setLevel(INFO)
support = boto3.client('support')
def describe_communications(case_id):
body = ''
try:
paginator = support.get_paginator('describe_communications')
page_iterator = paginator.paginate(caseId=case_id)
except ClientError as err:
logger.error(err.response['Error']['Message'])
raise
for page in page_iterator:
for communication in page['communications']:
body = re.sub(
r'-{3,}|={3,}|\*{3,}|_{3,}', "---", communication['body']
) + '\n\n---\n\n' + body
communications = '## Communications\n' + body
return communications
def create_payload(account_id, case_info):
token = os.environ['API_KEY']
title = '# ' + case_info['subject'] + '\n'
information = '## Case Information\n' + \
'* アカウント ID: ' + account_id + '\n' + \
'* ケース ID: ' + case_info['displayId'] + '\n' +\
'* 作成日: ' + case_info['timeCreated'] + '\n' + \
'* 重要度: ' + case_info['severityCode'] + '\n' + \
'* サービス: ' + case_info['serviceCode'] + '\n' + \
'* カテゴリ: ' + case_info['categoryCode'] + '\n'
communications = describe_communications(case_info['caseId'])
return {
'access_token': token,
'path': '/投稿したいパス/' + case_info['subject'],
'body': title + information + communications,
'grant': 1,
}
def describe_case(case_id):
try:
response = support.describe_cases(
caseIdList=[
case_id
],
includeResolvedCases=True,
includeCommunications=False
)
except ClientError as err:
logger.error(err.response['Error']['Message'])
raise
else:
return response['cases'][0]
def lambda_handler(event, context):
case_info = describe_case(event['detail']['case-id'])
if case_info['serviceCode'] == "service-limit-increase" or \
case_info['subject'] == "Enterprise Activation Request for Linked account.":
return {
'Result': 'Service limit increase or Enterprise support activation will not be posted.'
}
payload = create_payload(event['account'], case_info)
url = os.environ['API_URL']
headers = {
'Content-Type': 'application/json',
}
req = Request(url, json.dumps(payload).encode('utf-8'), headers)
try:
response = urlopen(req)
response.read()
except HTTPError as e:
return {
'Result': f'''Request failed: {e.code}, {e.reason})'''
}
except URLError as e:
return {
'Result': f'''Request failed: {e.reason})'''
}
else:
return {
'Result' : 'Knowledge posted.'
}