Last active
April 16, 2020 18:07
-
-
Save ccortezb/172fb73231466669a246ad97d4ca70ce to your computer and use it in GitHub Desktop.
Deploy Step Functions in Serverless Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paso 1: instalar serverless framework | |
sudo npm i -g serverless | |
paso 2: crear un proyecto vacío | |
serverless create --template aws-nodejs --path step-functions-demo | |
serverless.yml: | |
service: step-functions-demo | |
provider: | |
name: aws | |
runtime: nodejs12.x | |
functions: | |
hello: | |
handler: handler.hello | |
plugins: | |
- serverless-step-functions | |
paso 3: instalar el plugin de step functions: | |
serverless plugin install --name serverless-step-functions | |
paso 4: instalar AWS Pseudo Parameters | |
npm install --save-dev serverless-pseudo-parameters | |
y también agregarlo en el serverless.yml: | |
plugins: | |
- serverless-pseudo-parameters | |
Paso 5 Agregar bloque de lambdas y step functions en serverless.yml | |
functions: | |
hello: | |
handler: handler.hello | |
ciao: | |
handler: handler.ciao | |
stepFunctions: | |
stateMachines: | |
hellostepfunc1: | |
name: 'hello' | |
definition: | |
Comment: "A Hello World example" | |
StartAt: HelloWorld | |
States: | |
HelloWorld: | |
Type: Task | |
Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${opt:stage}-hello" | |
Next: CiaoWorld | |
CiaoWorld: | |
Type: Task | |
Resource: "arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${opt:stage}-ciao" | |
End: true | |
Paso 6: editar el handler.js | |
module.exports.hello = (event, context, callback) => { | |
callback(null, null); | |
}; | |
module.exports.ciao = (event, context, callback) => { | |
const response = { | |
statusCode: 200, | |
body: JSON.stringify({ | |
message: 'ciao world!' | |
}), | |
}; | |
callback(null, response); | |
}; | |
Paso 7: Deploy | |
serverless deploy -v | |
Paso 8: Invoke step functions | |
serverless invoke stepf -n hellostepfunc1 --stage dev | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment