Skip to content

Instantly share code, notes, and snippets.

@cm-fujii
Created December 18, 2019 00:42
Show Gist options
  • Save cm-fujii/d77a443ae0f2b6dcf8d69005132ce710 to your computer and use it in GitHub Desktop.
Save cm-fujii/d77a443ae0f2b6dcf8d69005132ce710 to your computer and use it in GitHub Desktop.
Amazon Connect Sample
import boto3
import os
import json
DESTINATION_PHONE_NUMBER = os.getenv('DESTINATION_PHONE_NUMBER')
SOURCE_PHONE_NUMBER = os.getenv('SOURCE_PHONE_NUMBER')
INSTANCE_ID = os.getenv('INSTANCE_ID')
CONTACT_FLOW_ID = os.getenv('CONTACT_FLOW_ID')
connect = boto3.client('connect')
def lambda_handler(event, context):
connect.start_outbound_voice_contact(
DestinationPhoneNumber=DESTINATION_PHONE_NUMBER,
ContactFlowId=CONTACT_FLOW_ID,
InstanceId=INSTANCE_ID,
SourcePhoneNumber=SOURCE_PHONE_NUMBER,
Attributes={
'message': 'これはテストメッセージです。'
}
)
import json
def lambda_handler(event, context):
print(json.dumps(event))
return {
'statusCode': 200
}
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AmazonConnectSample
Parameters:
DestinationPhoneNumber:
Type: String
SourcePhoneNumber:
Type: String
InstanceId:
Type: String
ContactFlowId:
Type: String
Globals:
Function:
Timeout: 5
Resources:
PhonePublishFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: phone-publish-function
CodeUri: src/publish
Handler: app.lambda_handler
Runtime: python3.7
Environment:
Variables:
DESTINATION_PHONE_NUMBER:
Ref: DestinationPhoneNumber
SOURCE_PHONE_NUMBER:
Ref: SourcePhoneNumber
INSTANCE_ID:
Ref: InstanceId
CONTACT_FLOW_ID:
Ref: ContactFlowId
Role: !GetAtt PhonePublishFunctionRole.Arn
PhonePublishFunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: phone-publish-function-role
PolicyDocument:
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: '*'
- Effect: Allow
Action:
- connect:StartOutboundVoiceContact
- connect:StopContact
Resource: '*'
PhoneSubscribeFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: phone-subscribe-function
CodeUri: src/subscribe
Handler: app.lambda_handler
Runtime: python3.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment