GreenAvenue / geranium

Geranium flower language is "encounter".
1 stars 0 forks source link

localstackのベースとなるdocker-composeを作成 #62

Closed rothr4 closed 4 years ago

rothr4 commented 4 years ago

このPRで解決すること

マージ条件

背景,前提知識

特記事項

rothr4 commented 4 years ago

Solved

rothr4 commented 4 years ago

Setup

Put the file as in the following example.

# geranium/packages/infra/
.
├── README.md
├── docker-compose.yml
└── scripts
    └── lambda.py
# lambda.py

import json

def lambda_handler(event, context):
    return response({'message': 'Hello LocalStack'}, 200)

def response(message, status_code):
    return {
        'statusCode': str(status_code),
        'body': json.dumps(message),
        'headers': {
            'Content-Type': 'application/json',
            'Access-Control-Allow-Origin': '*'
        },
    }

Execute command to make zip.

zip scripts/lambda.zip scripts/lambda.py

awscli

$ aws --endpoint-url=http://localhost:4574 \
--profile localstack lambda create-function \
--function-name=func_1 \
--runtime=python3.8 \
--role=r1 \
--handler=lambda.lambda_handler \
--zip-file fileb://scripts/lambda.zip
OhOG9a3aq6aCMgBxgTZyVt/kvMLz8HmkikU9DHSKEAI=    387             arn:aws:lambda:us-east-1:000000000000:function:func_1   func_1  lambda.lambda_handler   2020-03-13T16:29:30.326+0000    499766e4-59fa-4512-b6f7-92a8ea28f7e7    r1      python3.8       Active  3       $LATESTTRACINGCONFIG   PassThrough

View

local_stack_lambda

rothr4 commented 4 years ago

Sample to run cloud-formation on localstack

aws cloudformation --endpoint-url=http://localhost:4581 \
create-stack --template-body file://template/dynamodb.template.yaml \
--stack-name create-test
arn:aws:cloudformation:us-east-1:000000000000:stack/create-test/9164fd5f-30bb-40a7-bb6d-36ee69eaa6c3

View

local_stack_bbd