Skip to content

Commit

Permalink
aws lambda inline
Browse files Browse the repository at this point in the history
  • Loading branch information
omenking committed Mar 8, 2024
1 parent f1c9a35 commit c0239fb
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/aws_sam_cli_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
cd /workspace
curl -L "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip" -o "samcli.zip"
unzip samcli.zip -d sam-installation
sudo ./sam-installation/install
cd $THEIA_WORKSPACE_ROOT
5 changes: 5 additions & 0 deletions lambda/inline/.aws-sam/build.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is auto generated by SAM CLI build command

[function_build_definitions]

[layer_build_definitions]
12 changes: 12 additions & 0 deletions lambda/inline/.aws-sam/build/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
InlineLambda:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.12
PackageType: Zip
InlineCode: "def handler(event, context):\n message = 'Hello {} {}!'.format(event['first_name'],\
\ event['last_name']) \n print(\"Log this for me\")\n return { \n \
\ 'message' : message\n }"
11 changes: 11 additions & 0 deletions lambda/inline/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Install SAM CLI

```sh
./bin/aws_sam_cli_install.sh
```

# Install CFN Lint

```sh
brew install cfn-lint
```
19 changes: 19 additions & 0 deletions lambda/inline/bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e

# we need the absolute path of samconfig.toml
# because relative path was giving us trouble
root_path=$(realpath .)
template_path="${root_path}/template.yml"

# sam build
# ===================
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-building.html
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-build.html
# -------------------
# This will prepare the artifact to be uploaded to S3 by generating:
# .aws-sam/build/template.yml
echo "== SAM build..."
echo "using template: ${template_path}"
sam build \
--template-file "${template_path}"
25 changes: 25 additions & 0 deletions lambda/inline/bin/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -e

# we need the absolute path because relative path was giving us trouble
root_path=$(realpath .)
#config_path="$(realpath ..)/python.toml"

#if [ ! -f "$config_path" ]; then
# echo "$config_path does not exist."
# exit 1
#fi

# sam deploy
# ===================
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-deploying.html
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-deploy.html
# -------------------
echo "== SAM deploy..."
#echo "loading configuration: $config_path"

sam deploy \
--template-file "./.aws-sam/build/template.yaml" \
--stack-name "inline-lamba-py" \
--capabilities "CAPABILITY_IAM"
#--config-file "$config_path" \
11 changes: 11 additions & 0 deletions lambda/inline/bin/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e

# we need the absolute path because relative path was giving us trouble
root_path=$(realpath .)

# cfn-lint
# -------------------
# This will check our cloudformation template to ensure its valid format
echo "== CFN linting..."
cfn-lint "${root_path}/template.yml"
5 changes: 5 additions & 0 deletions lambda/inline/function/function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def handle(event, context):
message = 'Hello {} {}!'.format(event['first_name'], event['last_name'])
return {
'message' : message
}
17 changes: 17 additions & 0 deletions lambda/inline/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html
InlineLambda:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.12
PackageType: Zip
InlineCode: |
def handler(event, context):
message = 'Hello {} {}!'.format(event['first_name'], event['last_name'])
print("Log this for me")
return {
'message' : message
}

0 comments on commit c0239fb

Please sign in to comment.