AWS Serverless: Difference between revisions
Jump to navigation
Jump to search
Created page with "=Introduction= This is an example of how to set up a serverless framework function within AWS =Setup= Within AWS there are example templates for each piece of the infrastructure. For this we need to create a *S3 Bucket to hold the code *IAM::Role to describe the permissions *Lambda The function to run =Templates= I have copied the example templates for each component and highlighted the ones we need to change ==S3 Bucket== <syntaxhighlight lang="json"> </syntaxhighligh..." |
|||
Line 9: | Line 9: | ||
I have copied the example templates for each component and highlighted the ones we need to change | I have copied the example templates for each component and highlighted the ones we need to change | ||
==S3 Bucket== | ==S3 Bucket== | ||
Example can be found [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html here] | |||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
{ | |||
"Resources": { | |||
"S3Bucket": { | |||
"Type": "AWS::S3::Bucket", | |||
"DeletionPolicy": "Retain", | |||
"Properties": { | |||
"BucketName": "DOC-EXAMPLE-BUCKET" | |||
} | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
==IAM::Role== | ==IAM::Role== | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> |
Revision as of 23:43, 18 February 2022
Introduction
This is an example of how to set up a serverless framework function within AWS
Setup
Within AWS there are example templates for each piece of the infrastructure. For this we need to create a
- S3 Bucket to hold the code
- IAM::Role to describe the permissions
- Lambda The function to run
Templates
I have copied the example templates for each component and highlighted the ones we need to change
S3 Bucket
Example can be found here
{
"Resources": {
"S3Bucket": {
"Type": "AWS::S3::Bucket",
"DeletionPolicy": "Retain",
"Properties": {
"BucketName": "DOC-EXAMPLE-BUCKET"
}
}
}
}
IAM::Role
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"RootRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version" : "2012-10-17",
"Statement": [ {
"Effect": "Allow",
"Principal": {
"Service": [ "ec2.amazonaws.com" ]
},
"Action": [ "sts:AssumeRole" ]
} ]
},
"Path": "/"
}
},
"RolePolicies": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyName": "root",
"PolicyDocument": {
"Version" : "2012-10-17",
"Statement": [ {
"Effect": "Allow",
"Action": "*",
"Resource": "*"
} ]
},
"Roles": [ {
"Ref": "RootRole"
} ]
}
},
"RootInstanceProfile": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Path": "/",
"Roles": [ {
"Ref": "RootRole"
} ]
}
}
}
}