diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb79dd5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +.idea diff --git a/index.js b/index.js index 5271044..e09a05f 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ class ServerlessApiGWSqsPlugin { deleteStack() { this.setCloudFormation() var stackName = this.getStackName(this.options.stage, this.serverless.service.service) - + this.cloudformation.deleteStack({StackName: stackName}, function (err, data) { if (err) { this.serverless.cli.log("[CodeRecipe ApiGW SQS Plugin] Error: ", err.message); @@ -60,12 +60,15 @@ class ServerlessApiGWSqsPlugin { var stackName = this.getStackName(this.options.stage, this.serverless.service.service) var apiEndpoint = this.serverless.service.custom.apiGwSqs.apiEndpoint var queueName = this.serverless.service.custom.apiGwSqs.queueName + var queueDelay = this.serverless.service.custom.apiGwSqs.queueDelay var replaceStageName = new RegExp('STAGE_NAME', 'g'); var replaceApiEndpoint = new RegExp('API_ENDPOINT', 'g'); var replaceQueueName = new RegExp('QUEUE_NAME', 'g'); + var replaceQueueDelay = new RegExp('QUEUE_DELAY', 'g'); contents = contents.replace(replaceStageName, this.options.stage); contents = contents.replace(replaceApiEndpoint, apiEndpoint); contents = contents.replace(replaceQueueName, queueName); + contents = contents.replace(replaceQueueDelay, queueDelay); var params = { Capabilities: [ 'CAPABILITY_IAM' @@ -91,7 +94,7 @@ class ServerlessApiGWSqsPlugin { this.cloudformation.waitFor('stackCreateComplete', {StackName: stackName}, (err, data) => { if (err) { console.log(err.message); - } + } else { this.serverless.cli.log("[CodeRecipe ApiGW SQS Plugin] Updated ApiGW -> SQS") } @@ -109,7 +112,7 @@ class ServerlessApiGWSqsPlugin { this.cloudformation.waitFor('stackCreateComplete', {StackName: stackName}, (err, data) => { if (err) { console.log(err.message); - } + } else { this.serverless.cli.log("[CodeRecipe ApiGW SQS Plugin] Created Api GW -> SQS") } @@ -122,4 +125,4 @@ class ServerlessApiGWSqsPlugin { } } -module.exports = ServerlessApiGWSqsPlugin; \ No newline at end of file +module.exports = ServerlessApiGWSqsPlugin; diff --git a/template.yml b/template.yml index 83c1552..fd50d97 100644 --- a/template.yml +++ b/template.yml @@ -3,6 +3,7 @@ Resources: Type: "AWS::SQS::Queue" Properties: QueueName: STAGE_NAME-QUEUE_NAME + DelaySeconds : QUEUE_DELAY ProxyApi: Type: AWS::ApiGateway::RestApi @@ -53,10 +54,10 @@ Resources: "application/json": "" Uri: !Sub arn:aws:apigateway:us-east-1:sqs:path/${AWS::AccountId}/${SQSQueue.QueueName} - APIGatewayDeployment: + APIGatewayDeployment: Type: AWS::ApiGateway::Deployment DependsOn: SQSAPIMethod - Properties: + Properties: RestApiId: !Sub "${ProxyApi}" StageName: STAGE_NAME @@ -72,7 +73,7 @@ Resources: - apigateway.amazonaws.com Action: sts:AssumeRole Policies: - - + - PolicyName: STAGE_NAME-QUEUE_NAME-policy PolicyDocument: Version: '2012-10-17' @@ -91,4 +92,4 @@ Resources: Outputs: ApiGwUrl: - Value: !Sub "https://${ProxyApi}.execute-api.${AWS::Region}.amazonaws.com/STAGE_NAME/API_ENDPOINT" \ No newline at end of file + Value: !Sub "https://${ProxyApi}.execute-api.${AWS::Region}.amazonaws.com/STAGE_NAME/API_ENDPOINT"