There are three primary ways which the service health check slackbot works.
-
Scheduled via Cloudwatch Event
-
Via the API Gateway URL:
curl -s https://$API_ID.execute-api.us-west-2.amazonaws.com/prod/aws_status
- Custom slash command:
/aws_status
- Build a
Custom Integration
usingIncoming WebHooks
to the desired channel (e.g. #aws_health). - Add the incoming webhooks integration and enter "AWS Health" for the
Customize Name
(additionally customize the Descriptive Label and icon if desired). - Note the
Webhook URL
and save the settings.
The CLI commands below require the following environmental variables:
AWS_DEFAULT_REGION=us-west-2
AWS_DEFAULT_PROFILE=aws_profile
AWS_SECRET_ACCESS_KEY=########################################
AWS_ACCESS_KEY_ID=AKIA################
$ aws sdb create-domain \
--domain-name aws-status
--profile aws_profile
(and capture output to $ROLE_ARN)
$ ROLE_ARN=$(aws iam create-role \
--role-name lambda_aws_status \
--assume-role-policy-document '{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Principal": {"Service": "lambda.amazonaws.com"},
"Action": "sts:AssumeRole"
}
}' \
--query 'Role.Arn' \
--output text)
$ aws iam put-role-policy \
--role-name lambda_aws_status \
--policy-name lambda_aws_status \
--policy-document file://lambda_aws_status_policy.json
-
Edit
aws_status.py
and edit as needed (i.e. provide Slack channel webhook URL). -
Create the
Lambda
package:
$ sh create_lambda_package.sh
$ aws lambda create-function \
--function-name aws_status \
--zip-file fileb://aws_status.zip \
--role $ROLE_ARN \
--handler aws_status.lambda_handler \
--runtime python2.7 \
--timeout 5
$ ACCT_ID=$(aws ec2 describe-security-groups \
--group-names 'Default' \
--query 'SecurityGroups[0].OwnerId' \
--output text) ; \
echo "account_id: $ACCT_ID"
$ API_ID=$(aws apigateway create-rest-api \
--name aws_status \
--query 'id' \
--output text) ;\
echo "api_id: $API_ID"
$ ROOT_ID=$(aws apigateway get-resources \
--rest-api-id $API_ID \
--query 'items[].id' \
--output text) ;\
echo "root_id: $ROOT_ID"
$ RESOURCE_ID=$(aws apigateway create-resource \
--rest-api-id $API_ID \
--parent-id $ROOT_ID \
--path-part aws_status \
--query 'id' \
--output text) ;\
echo "resource_id: $RESOURCE_ID"
$ aws apigateway put-method \
--rest-api-id $API_ID \
--resource-id $RESOURCE_ID \
--http-method GET \
--authorization-type NONE
$ aws apigateway put-integration \
--rest-api-id $API_ID \
--resource-id $RESOURCE_ID \
--http-method GET \
--type AWS \
--integration-http-method POST \
--uri "arn:aws:apigateway:us-west-2:lambda:path//2015-03-31/functions/arn:aws:lambda:us-west-2:$ACCT_ID:function:aws_status/invocations"
$ aws apigateway put-integration-response \
--rest-api-id $API_ID \
--resource-id $RESOURCE_ID \
--http-method GET \
--status-code 200 \
--response-templates "{\"application/json\": \"\"}"
$ aws apigateway put-method-response \
--rest-api-id $API_ID \
--resource-id $RESOURCE_ID \
--http-method GET \
--status-code 200 \
--response-models "{\"application/json\": \"Empty\"}"
$ aws apigateway create-deployment \
--rest-api-id $API_ID \
--stage-name prod
$ aws lambda add-permission \
--function-name aws_status \
--statement-id apigateway-aws_status \
--principal apigateway.amazonaws.com \
--action lambda:InvokeFunction \
--source-arn "arn:aws:execute-api:us-west-2:$ACCT_ID:$API_ID/*/GET/aws_status"
$ aws events put-rule \
--name lambda_aws_status_cron_3m \
--schedule-expression "rate(3 minutes)"
$ FUNC_ARN=$(aws lambda get-function \
--function-name aws_status \
--query 'Configuration.FunctionArn' \
--output text)
$ aws events put-targets \
--rule lambda_aws_status_cron_3m \
--targets Id=1,Arn=$FUNC_ARN
- Build another Custom Integration with
Slash Commands
. - Enter "/aws_status" in the
Choose a Command
field thenAdd Slash Command Integration
. - Enter "https://$API_ID.execute-api.us-west-2.amazonaws.com/prod/aws_status" as
Invoke URL
where$API_ID
is the API Gateway REST API ID. - Set
Method
toGET
. - Enter "AWS Health" for
Customize Name
. - Under
Autocomplete help text
, checkShow this command in the autocomplete list
and enter "Check AWS Service Health Dashboard for events". Save Integration
.