Skip to content

Commit d979324

Browse files
committed
commitv1
1 parent 3c53f0f commit d979324

6 files changed

Lines changed: 208 additions & 13 deletions

File tree

_pattern-model/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# AWS Service 1 to AWS Service 2
22

3-
This pattern << explain usage >>
3+
This pattern shows an example how a phone number can be validated and how a SMS message can be send using Pinpoint APIs which via API Gateway and Lambda deployed using SAM.
4+
5+
As a pre-requisite, a Pinpoint Application has to be created and its SMS channel should be enabled. Subsequently, this stack can be deployed with pinpoint application id, destination phone number, message that has to be sent, origination number and message type. Please read more about the Pinpoint API calls utilised here:
6+
https://docs.aws.amazon.com/pinpoint/latest/apireference/apps-application-id-messages.html#apps-application-id-messagespost
7+
8+
https://docs.aws.amazon.com/pinpoint/latest/apireference/phone-number-validate.html
49

510
Learn more about this pattern at Serverless Land Patterns: << Add the live URL here >>
611

_pattern-model/template.yaml

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,61 @@
11
AWSTemplateFormatVersion: '2010-09-09'
22
Transform: AWS::Serverless-2016-10-31
3-
Description: Serverless patterns - Service to Service description
4-
5-
# Comment on each global
6-
Globals:
7-
8-
9-
# Comment each resource section to explain usage
103
Resources:
11-
12-
13-
# List all common outputs for usage
14-
Outputs:
15-
4+
Api:
5+
Type: AWS::Serverless::Api
6+
Properties:
7+
Name: !Sub
8+
- ${ResourceName} From Stack ${AWS::StackName}
9+
- ResourceName: PinpointSMSApigw
10+
StageName: Prod
11+
DefinitionBody:
12+
openapi: '3.0'
13+
info: {}
14+
paths:
15+
/send_message:
16+
post:
17+
x-amazon-apigateway-integration:
18+
httpMethod: POST
19+
type: aws_proxy
20+
uri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${PinpointFunction.Arn}/invocations
21+
responses: {}
22+
EndpointConfiguration: REGIONAL
23+
TracingEnabled: true
24+
PinpointFunction:
25+
Type: AWS::Serverless::Function
26+
Properties:
27+
Description: !Sub
28+
- Stack ${AWS::StackName} Function ${ResourceName}
29+
- ResourceName: PinpointFunction
30+
CodeUri: code/
31+
Handler: lambda_function.lambda_handler
32+
Runtime: python3.9
33+
MemorySize: 3008
34+
Timeout: 30
35+
Tracing: Active
36+
Events:
37+
ApiPOSTsendmessage:
38+
Type: Api
39+
Properties:
40+
Path: /send_message
41+
Method: POST
42+
RestApiId: !Ref Api
43+
Policies:
44+
- Statement:
45+
- Effect: Allow
46+
Action:
47+
- "mobiletargeting:PhoneNumberValidate"
48+
Resource: !Join
49+
- ""
50+
- - "arn:aws:mobiletargeting:*:"
51+
- !Ref AWS::AccountId
52+
- ":phone/number/validate"
53+
- Effect: Allow
54+
Action:
55+
- "mobiletargeting:SendMessages"
56+
Resource: !Join
57+
- ""
58+
- - "arn:aws:mobiletargeting:*:"
59+
- !Ref AWS::AccountId
60+
- ":apps/*/messages"
1661

apigw-lambda-pinpoint/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# AWS Service 1 to AWS Service 2
2+
3+
This pattern << explain usage >>
4+
5+
Learn more about this pattern at Serverless Land Patterns: << Add the live URL here >>
6+
7+
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
8+
9+
## Requirements
10+
11+
* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
12+
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
13+
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
14+
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
15+
16+
## Deployment Instructions
17+
18+
1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
19+
```
20+
git clone https://github.com/aws-samples/serverless-patterns
21+
```
22+
1. Change directory to the pattern directory:
23+
```
24+
cd _patterns-model
25+
```
26+
1. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file:
27+
```
28+
sam deploy --guided
29+
```
30+
1. During the prompts:
31+
* Enter a stack name
32+
* Enter the desired AWS Region
33+
* Allow SAM CLI to create IAM roles with the required permissions.
34+
35+
Once you have run `sam deploy --guided` mode once and saved arguments to a configuration file (samconfig.toml), you can use `sam deploy` in future to use these defaults.
36+
37+
1. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.
38+
39+
## How it works
40+
41+
Explain how the service interaction works.
42+
43+
## Testing
44+
45+
Provide steps to trigger the integration and show what should be observed if successful.
46+
47+
## Cleanup
48+
49+
1. Delete the stack
50+
```bash
51+
aws cloudformation delete-stack --stack-name STACK_NAME
52+
```
53+
1. Confirm the stack has been deleted
54+
```bash
55+
aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"
56+
```
57+
----
58+
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
59+
60+
SPDX-License-Identifier: MIT-0
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"title": "Step Functions to Athena",
3+
"description": "Create a Step Functions workflow to query Amazon Athena.",
4+
"language": "Python",
5+
"level": "200",
6+
"framework": "CDK",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"This sample project demonstrates how to use an AWS Step Functions state machine to query Athena and get the results. This pattern is leveraging the native integration between these 2 services which means only JSON-based, structured language is used to define the implementation.",
11+
"With Amazon Athena you can get up to 1000 results per invocation of the GetQueryResults method and this is the reason why the Step Function has a loop to get more results. The results are sent to a Map which can be configured to handle (the DoSomething state) the items in parallel or one by one by modifying the max_concurrency parameter.",
12+
"This pattern deploys one Step Functions, two S3 Buckets, one Glue table and one Glue database."
13+
]
14+
},
15+
"gitHub": {
16+
"template": {
17+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/sfn-athena-cdk-python",
18+
"templateURL": "serverless-patterns/sfn-athena-cdk-python",
19+
"projectFolder": "sfn-athena-cdk-python",
20+
"templateFile": "sfn_athena_cdk_python/sfn_athena_cdk_python_stack.py"
21+
}
22+
},
23+
"resources": {
24+
"bullets": [
25+
{
26+
"text": "Call Athena with Step Functions",
27+
"link": "https://docs.aws.amazon.com/step-functions/latest/dg/connect-athena.html"
28+
},
29+
{
30+
"text": "Amazon Athena - Serverless Interactive Query Service",
31+
"link": "https://aws.amazon.com/athena/"
32+
}
33+
]
34+
},
35+
"deploy": {
36+
"text": [
37+
"sam deploy"
38+
]
39+
},
40+
"testing": {
41+
"text": [
42+
"See the GitHub repo for detailed testing instructions."
43+
]
44+
},
45+
"cleanup": {
46+
"text": [
47+
"Delete the stack: <code>cdk delete</code>."
48+
]
49+
},
50+
"authors": [
51+
{
52+
"name": "Your name",
53+
"image": "link-to-your-photo.jpg",
54+
"bio": "Your bio.",
55+
"linkedin": "linked-in-ID",
56+
"twitter": "twitter-handle"
57+
}
58+
]
59+
}

apigw-lambda-pinpoint/src/app.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*! Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* SPDX-License-Identifier: MIT-0
3+
*/
4+
5+
'use strict'
6+
7+
exports.handler = async (event) => {
8+
// Lambda handler code
9+
console.log(JSON.stringify(event, 0, null))
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
Description: Serverless patterns - Service to Service description
4+
5+
# Comment on each global
6+
Globals:
7+
8+
9+
# Comment each resource section to explain usage
10+
Resources:
11+
12+
13+
# List all common outputs for usage
14+
Outputs:
15+
16+

0 commit comments

Comments
 (0)