# Create project directory $ mkdir amazing-api # Create project using boilerplate $ sls create --template aws-python Modify the service as required $ edit `serverless.yml` file Modify function text $ edit `handler.py` file
# Deploy function $ sls deploy # Invoke remote function $ sls invoke --function hello # Invoke function locally $ sls invoke local --function hello
--------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
[root@ip-172-31-82-149 ~]# mkdir amazing-api [root@ip-172-31-82-149 ~]# ls amazing-api anaconda-ks.cfg original-ks.cfg [root@ip-172-31-82-149 ~]# cd amazing-api/ [root@ip-172-31-82-149 amazing-api]# ls [root@ip-172-31-82-149 amazing-api]# sls create --template aws-python Serverless: Generating boilerplate... _______ __ | _ .-----.----.--.--.-----.----| .-----.-----.-----. | |___| -__| _| | | -__| _| | -__|__ --|__ --| |____ |_____|__| \___/|_____|__| |__|_____|_____|_____| | | | The Serverless Application Framework | | serverless.com, v1.52.0 -------' Serverless: Successfully generated boilerplate for template: "aws-python" Serverless: NOTE: Please update the "service" property in serverless.yml with your service name [root@ip-172-31-82-149 amazing-api]# ls handler.py serverless.yml [root@ip-172-31-82-149 amazing-api]# cat handler.py import json def hello(event, context): body = { "message": "Go Serverless v1.0! Your function executed successfully!", "input": event } response = { "statusCode": 200, "body": json.dumps(body) } return response # Use this code if you don't use the http event with the LAMBDA-PROXY # integration """ return { "message": "Go Serverless v1.0! Your function executed successfully!", "event": event } """ [root@ip-172-31-82-149 amazing-api]# cat serverless.yml # Welcome to Serverless! # # This file is the main config file for your service. # It's very minimal at this point and uses default values. # You can always add more config options for more control. # We've included some commented out config examples here. # Just uncomment any of them to get that config option. # # For full config options, check the docs: # docs.serverless.com # # Happy Coding! service: amazing-api # app and org for use with dashboard.serverless.com #app: your-app-name #org: your-org-name # You can pin your service to only deploy with a specific Serverless version # Check out our docs for more details # frameworkVersion: "=X.X.X" provider: name: aws runtime: python2.7 # you can overwrite defaults here # stage: dev # region: us-east-1 # you can add statements to the Lambda function's IAM Role here # iamRoleStatements: # - Effect: "Allow" # Action: # - "s3:ListBucket" # Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] } # - Effect: "Allow" # Action: # - "s3:PutObject" # Resource: # Fn::Join: # - "" # - - "arn:aws:s3:::" # - "Ref" : "ServerlessDeploymentBucket" # - "/*" # you can define service wide environment variables here # environment: # variable1: value1 # you can add packaging information here #package: # include: # - include-me.py # - include-me-dir/** # exclude: # - exclude-me.py # - exclude-me-dir/** functions: hello: handler: handler.hello # The following are a few example events you can configure # NOTE: Please make sure to change your handler code to work with those events # Check the event documentation for details # events: # - http: # path: users/create # method: get # - websocket: $connect # - s3: ${env:BUCKET} # - schedule: rate(10 minutes) # - sns: greeter-topic # - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000 # - alexaSkill: amzn1.ask.skill.xx-xx-xx-xx # - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx # - iot: # sql: "SELECT * FROM 'some_topic'" # - cloudwatchEvent: # event: # source: # - "aws.ec2" # detail-type: # - "EC2 Instance State-change Notification" # detail: # state: # - pending # - cloudwatchLog: '/aws/lambda/hello' # - cognitoUserPool: # pool: MyUserPool # trigger: PreSignUp # - alb: # listenerArn: arn:aws:elasticloadbalancing:us-east-1:XXXXXX:listener/app/my-load-balancer/50dc6c495c0c9188/ # priority: 1 # conditions: # host: example.com # path: /hello # Define function environment variables here # environment: # variable2: value2 # you can add CloudFormation resource templates here #resources: # Resources: # NewResource: # Type: AWS::S3::Bucket # Properties: # BucketName: my-new-bucket # Outputs: # NewOutput: # Description: "Description for the output" # Value: "Some output value" [root@ip-172-31-82-149 amazing-api]# ls handler.py serverless.yml [root@ip-172-31-82-149 amazing-api]# ve serverless.yml -bash: ve: command not found [root@ip-172-31-82-149 amazing-api]# vi serverless.yml [root@ip-172-31-82-149 amazing-api]# vi handler.py [root@ip-172-31-82-149 amazing-api]#
[root@ip-172-31-82-149 amazing-api]# sls deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless Error ---------------------------------------
AWS provider credentials not found. Learn how to set up AWS provider credentials in our docs here: <http://slss.io/aws-creds-setup>.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
Operating System: linux
Node Version: 10.14.1
Framework Version: 1.52.0
Plugin Version: 2.0.0
SDK Version: 2.1.1
[root@ip-172-31-82-149 amazing-api]# export AWS_ACCESS_KEY_ID=AKIAWSYHFCM3Y6ZLJWN6
[root@ip-172-31-82-149 amazing-api]# export AWS_SECRET_ACCESS_KEY=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
[root@ip-172-31-82-149 amazing-api]# serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
.....
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service amazing-api.zip file to S3 (407 B)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
................
Serverless: Stack update finished...
Service Information
service: amazing-api
stage: dev
region: us-east-1
stack: amazing-api-dev
resources: 5
api keys:
None
endpoints:
None
functions:
hello: amazing-api-dev-hello
layers:
None
Serverless: Run the "serverless" command to setup monitoring, troubleshooting and testing.
[root@ip-172-31-82-149 amazing-api]#
[root@ip-172-31-82-149 amazing-api]# sls invoke --function hello { "body": "{\"input\": {}, \"message\": \"Welcome to Raj by serverless\"}", "statusCode": 200 } [root@ip-172-31-82-149 amazing-api]#
[root@ip-172-31-82-149 amazing-api]# sls invoke --function hello { "body": "{\"input\": {}, \"message\": \"Welcome to Raj by serverless\"}", "statusCode": 200 } [root@ip-172-31-82-149 amazing-api]#
Hello everyone , here’s your opportunity for you to achieve your dreams of being a multi million dollar rich through trading , I once loss all I got through trading but was fortunate to come across a woman with great virtue and selfless heart (Mary ) i was introduce to her masterclass strategy while searching online which has revived me of all my losses and made me gain more and more . With her unique strategy you are entitled to daily signals and instant withdraw ,be rest assured of getting a refund of all your loss investment with any platform that has denied you in one way or the other in getting your money . Mrs Mary masterclass strategy is simply the best for beginners and those that are finding it difficult to succeed through trading she’ll help you with just a simple step . Email her ( maryshea03 @ Gmail .com) WhatsApp +1 562 384 7738 . Remember this is absolutely free!!!
ReplyDeleteThank you for your post. This is useful information.
ReplyDeleteDevOps Training
DevOps Online Training
DevOps Training in Ameerpet
Best of Trending Techniques of AWS - Amazon Web Services,
ReplyDeleteAWS course Training in Bangalore
Best AWS Training Institutes in Bangalore
Cloud Computing courses in Bangalore
AWS course in Bangalore
Thanks for Sharing the AWS or Amazon Web Services Career's Training Courses and Certificates for Freshers and Experience Candidates.
ReplyDeleteAWS Training in Bangalore
Best AWS Training Institutes in Bangalore
Cloud Computing courses in Bangalore
AWS course in Bangalore
Thanks you and excellent and good to see the best software training courses for freshers and experience candidates to upgade the next level in an Software Industries Technologies,
ReplyDeletePython course in Bangalore
Python Training in Bangalore
AWS Training in Bangalore
AWS course in Bangalore
AngularJS Training in Bangalore
AngularJS Course in Bangalore
Data Science Course in Bangalore
Data Science Training in Bangalore
Machine Learning Training in Bangalore
Machine Learning Course in Bangalore
That is a great tip especially to those new to the blogosphere. Short but
ReplyDeletevery accurate info… Thank you for sharing this one. A must read post!
Hadoop Training in Bangalore
Python Training in Bangalore
AWS Training in Bangalore
UI Development training in Bangalore
Machine Learning Training in Bangalore
Machine Learning Training with Python in Bangalore
Data Science Using Python Training in Bangalore