Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (73 sloc) 2.55 KB
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
CorsOrigin:
Type: String
Default: ''
Description: (Optional) Cross-origin resource sharing (CORS) Origin. You can specify a single origin, all "*" or leave empty and no CORS will be applied.
MaxLength: 250
SSMParameterPrefix:
Type: String
Default: 'lambda-stripe-charge'
Description: >
This component assumes the Stripe Secret key needed to use the Stripe Charge API is stored as SecureStrings in SSM Parameter Store under the prefix defined by
this parameter. See the component README for details.
AllowedPattern: ^[0-9a-zA-Z-][0-9a-zA-Z-\/]+
ConstraintDescription: 'Must start with alphanumeric characters (excluding a slash)'
Conditions:
IsCorsDefined: !Not [!Equals [!Ref CorsOrigin, '']]
Resources:
ChargeStripeApiWebhook:
Type: AWS::Serverless::Api
Properties:
StageName: prod
DefinitionBody:
swagger: 2.0
info:
title:
Ref: AWS::StackName
paths:
/charge:
post:
responses: {}
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${CreateStripeCharge.Arn}/invocations
CreateStripeCharge:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs8.10
Timeout: 10
Policies:
- SNSCrudPolicy:
TopicName: !GetAtt SNSTopic.TopicName
- Statement:
Effect: Allow
Action:
- ssm:GetParameter
Resource: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${SSMParameterPrefix}/*
Environment:
Variables:
IS_CORS: IsCorsDefined
CORS_ORIGIN: !Ref CorsOrigin
SSM_PARAMETER_PREFIX: !Ref SSMParameterPrefix
TOPIC_ARN: !Ref SNSTopic
Events:
Api:
Type: Api
Properties:
Path: /charge
Method: POST
RestApiId: !Ref ChargeStripeApiWebhook
SNSTopic:
Type: AWS::SNS::Topic
Outputs:
ApiUrl:
Value: !Sub https://${ChargeStripeApiWebhook}.execute-api.${AWS::Region}.amazonaws.com/prod/charge
Description: The URL of the API Gateway you provide to Stripe as a webhook it invokes to make a charge based on its token.
SNSTopic:
Value: !Ref SNSTopic
Description: The SNS topic your Stripe Lambda is notifying to
You can’t perform that action at this time.