# Create temp folder for the tutorialmkdir/tmp/serverless-tutorialcd/tmp/serverless-tutorial# Install Serverless clinpminstall-gserverless# Generate templateserverless#Choose first one (AWS / Node.js / HTTP API)## Indicate a name like "Tutorial"## Login/Register## Create A New App## Indicate a name like "tutorialapp)
exports.hello=async (event) => {return {statusCode:200,body:JSON.stringify({message:"Go Serverless v4! Your function executed successfully!",}),};};
# "org" ensures this Service is used with the correct Serverless Framework Access Key.org:testing12342# "app" enables Serverless Framework Dashboard features and sharing them with other Services.app:tutorialapp# "service" is the name of this project. This will also be added to your AWS resource names.service:Tutorialprovider:name:awsruntime:nodejs20.xfunctions:hello:handler:handler.helloevents:- httpApi:path:/method:get
```yaml Description: This stack creates an IAM role that can be used by Serverless Framework for use in deployments. Resources: SFRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: AWS: arn:aws:iam::486128539022:root Action: - sts:AssumeRole Condition: StringEquals: sts:ExternalId: !Sub 'ServerlessFramework-${OrgUid}' Path: / RoleName: !Ref RoleName ManagedPolicyArns: - arn:aws:iam::aws:policy/AdministratorAccess ReporterFunction: Type: Custom::ServerlessFrameworkReporter Properties: ServiceToken: 'arn:aws:lambda:us-east-1:486128539022:function:sp-providers-stack-reporter-custom-resource-prod-tmen2ec' OrgUid: !Ref OrgUid RoleArn: !GetAtt SFRole.Arn Alias: !Ref Alias Outputs: SFRoleArn: Description: 'ARN for the IAM Role used by Serverless Framework' Value: !GetAtt SFRole.Arn Parameters: OrgUid: Description: Serverless Framework Org Uid Type: String Alias: Description: Serverless Framework Provider Alias Type: String RoleName: Description: Serverless Framework Role Name Type: String ```
# "org" ensures this Service is used with the correct Serverless Framework Access Key.org:testing12342# "app" enables Serverless Framework Dashboard features and sharing them with other Services.app:tutorialapp# "service" is the name of this project. This will also be added to your AWS resource names.service:Tutorialprovider:name:awsruntime:nodejs20.xenvironment:DYNAMODB_CUSTOMER_TABLE:${self:service}-customerTable-${sls:stage}iam:role:statements:- Effect:'Allow'Action:- 'dynamodb:PutItem'- 'dynamodb:Get*'- 'dynamodb:Scan*'- 'dynamodb:UpdateItem'- 'dynamodb:DeleteItem'Resource:arn:aws:dynamodb:${aws:region}:${aws:accountId}:table/${self:service}-customerTable-${sls:stage}functions:hello:handler:handler.helloevents:- httpApi:path:/method:getcreateCustomer:handler:createCustomer.createCustomerevents:- httpApi:path:/method:postresources:Resources:CustomerTable:Type:AWS::DynamoDB::TableProperties:AttributeDefinitions:- AttributeName:primary_keyAttributeType:SBillingMode:PAY_PER_REQUESTKeySchema:- AttributeName:primary_keyKeyType:HASHTableName:${self:service}-customerTable-${sls:stage}
javascriptCopy code// Example in Node.jsexports.hello=async (event) => {try {// Function logic} catch (error) {console.error(error);return {statusCode:500,body:JSON.stringify({ message:'Internal Server Error' }),};}};