Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Conversation

@studio3104
Copy link
Contributor

Just as titled

@kazfuku
Copy link

kazfuku commented Apr 9, 2020

  • package.json の aws-cdk 系のバージョンがずれていて、TypeScript がコンパイルできませんでした。1.30.0 に統一したら通りました。
(python-rapid-prototyping-JK5mR3Nq-py3.8) bash-3.2$ bash scripts/samlocal.sh
Using default tag: latest
latest: Pulling from amazon/dynamodb-local
Digest: sha256:8414d80019b0502742c98e66ea22780f99c9d7c118696dc78eef7867a705e7bb
Status: Image is up to date for amazon/dynamodb-local:latest
docker.io/amazon/dynamodb-local:latest
dd4392339e6c        lambda-local        bridge              local

ac45478bb4a0
ac45478bb4a0
890958f719e89e709b18656a224c1966684c185e13d26e256bcc4b7ca820b1c3
{
    "TableDescription": {
        "TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/testUserTable", 
        "AttributeDefinitions": [
            {
                "AttributeName": "user_id", 
                "AttributeType": "S"
            }
        ], 
        "ProvisionedThroughput": {
            "NumberOfDecreasesToday": 0, 
            "WriteCapacityUnits": 0, 
            "LastIncreaseDateTime": 0.0, 
            "ReadCapacityUnits": 0, 
            "LastDecreaseDateTime": 0.0
        }, 
        "TableSizeBytes": 0, 
        "TableName": "testUserTable", 
        "BillingModeSummary": {
            "LastUpdateToPayPerRequestDateTime": 1586395173.623, 
            "BillingMode": "PAY_PER_REQUEST"
        }, 
        "TableStatus": "ACTIVE", 
        "KeySchema": [
            {
                "KeyType": "HASH", 
                "AttributeName": "user_id"
            }
        ], 
        "ItemCount": 0, 
        "CreationDateTime": 1586395173.623
    }
}
⨯ Unable to compile TypeScript:
lib/database-stack.ts:10:41 - error TS2345: Argument of type 'this' is not assignable to parameter of type 'Construct'.
  Type 'DatabaseStack' is missing the following properties from type 'Construct': onValidate, onPrepare, onSynthesize

10         this.table = new dynamodb.Table(this, 'UserTable', {
                                           ~~~~

Subprocess exited with error 1
(python-rapid-prototyping-JK5mR3Nq-py3.8) bash-3.2$ cdk --version
1.28.0 (build 5f2bbc6)
(python-rapid-prototyping-JK5mR3Nq-py3.8) bash-3.2$ cat provisioning/package.json 
{
  "name": "provisioning",
  "version": "0.1.0",
  "bin": {
    "provisioning": "bin/provisioning.js"
  },
  "scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "test": "jest",
    "cdk": "cdk"
  },
  "devDependencies": {
    "@aws-cdk/assert": "1.23.0",
    "@types/jest": "^24.0.22",
    "@types/node": "10.17.5",
    "aws-cdk": "^1.28.0",
    "jest": "^24.9.0",
    "ts-jest": "^24.1.0",
    "ts-node": "^8.8.1",
    "typescript": "~3.7.2"
  },
  "dependencies": {
    "@aws-cdk/aws-apigateway": "^1.30.0",
    "@aws-cdk/aws-dynamodb": "^1.30.0",
    "@aws-cdk/aws-lambda": "^1.30.0",
    "@aws-cdk/core": "1.28.0",
    "source-map-support": "^0.5.16"
  }
}

@kazfuku
Copy link

kazfuku commented Apr 9, 2020

  • scripts/samlocal.sh は動いたのですが、APIGW の PUT /user や GET /user/{user_id} を呼ぶと、Lambda がエラーになりました
$ bash -x scripts/samlocal.sh
+ set -e
++ dirname scripts/samlocal.sh
+ CWD=scripts
+ DOCKER_NETWORK_NAME=lambda-local
+ DDB_TABLE_NAME=testUserTable
+ DDB_CONTAINER_PREFIX=dynamodblocalpythonrapid
++ date +%Y%m%d%H%M%S
+ DDB_CONTAINER_NAME=dynamodblocalpythonrapid20200409121701
+ DDB_LOCAL_PORT=8001
++ docker ps -aq --filter name=dynamodblocalpythonrapid
+ EXISTING_CONTAINERS=0c5db83e3538
+ PATH_TO_ENVVAR=/tmp/pythonrapidenv.json
+ docker pull amazon/dynamodb-local
Using default tag: latest
latest: Pulling from amazon/dynamodb-local
Digest: sha256:8414d80019b0502742c98e66ea22780f99c9d7c118696dc78eef7867a705e7bb
Status: Image is up to date for amazon/dynamodb-local:latest
docker.io/amazon/dynamodb-local:latest
+ docker network ls
+ grep lambda-local
dd4392339e6c        lambda-local        bridge              local
+ echo

+ '[' '!' x0c5db83e3538 = x ']'
+ docker stop 0c5db83e3538
0c5db83e3538
+ docker rm 0c5db83e3538
0c5db83e3538
+ docker run -d --name dynamodblocalpythonrapid20200409121701 --net lambda-local -p 8001:8000 amazon/dynamodb-local
14541e3c7ba31b89325877aca62c5336303881eac2c6888a1a0a2e89321f1f57
+ /usr/local/bin/aws dynamodb create-table --endpoint-url http://localhost:8001 --table-name testUserTable --attribute-definitions AttributeName=user_id,AttributeType=S --key-schema AttributeName=user_id,KeyType=HASH --billing-mode PAY_PER_REQUEST
{
    "TableDescription": {
        "TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/testUserTable", 
        "AttributeDefinitions": [
            {
                "AttributeName": "user_id", 
                "AttributeType": "S"
            }
        ], 
        "ProvisionedThroughput": {
            "NumberOfDecreasesToday": 0, 
            "WriteCapacityUnits": 0, 
            "LastIncreaseDateTime": 0.0, 
            "ReadCapacityUnits": 0, 
            "LastDecreaseDateTime": 0.0
        }, 
        "TableSizeBytes": 0, 
        "TableName": "testUserTable", 
        "BillingModeSummary": {
            "LastUpdateToPayPerRequestDateTime": 1586402228.407, 
            "BillingMode": "PAY_PER_REQUEST"
        }, 
        "TableStatus": "ACTIVE", 
        "KeySchema": [
            {
                "KeyType": "HASH", 
                "AttributeName": "user_id"
            }
        ], 
        "ItemCount": 0, 
        "CreationDateTime": 1586402228.407
    }
}
+ echo '{"Parameters": {"DYNAMODB_ENDPOINT_URL": "http://dynamodblocalpythonrapid20200409121701:8001", "DYNAMODB_TABLE_NAME": "testUserTable"}}'
+ jq .
+ cd scripts/../provisioning
+ cdk synth
Successfully synthesized to /Users/kazshima/git/aws-rapid-prototyping-with-python/provisioning/cdk.out
Supply a stack id (DatabaseStack, ApiStack) to display its template.
+ sam local start-api --template-file cdk.out/ApiStack.template.json --docker-network lambda-local --env-vars /tmp/pythonrapidenv.json
Mounting UserFunction at http://127.0.0.1:3000/user/{user_id} [DELETE, GET, PATCH]
Mounting UserFunction at http://127.0.0.1:3000/user [PUT]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2020-04-09 12:17:24  * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
Invoking app.dispatch_request (python3.8)

Fetching lambci/lambda:python3.8 Docker container image......
Mounting /Users/kazshima/git/aws-rapid-prototyping-with-python/provisioning/cdk.out/asset.dc8d124f9a0ae1b9ae0ecf856f76b2c211948badf6e0990ac449e89142603ad8 as /var/task:ro,delegated inside runtime container
START RequestId: 62f2a2b8-8717-1122-f5ed-19df2268cefb Version: $LATEST
[ERROR] ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the GetItem operation: Requested resource not found
Traceback (most recent call last):
  File "/var/task/app.py", line 109, in dispatch_request
    return PATHS[request_path].dispatch(event)
  File "/var/task/app.py", line 26, in dispatch
    status_code, body = getattr(cls, event['httpMethod'].lower())(event)
  File "/var/task/app.py", line 37, in get
    response = table.get_item(Key={'user_id': user_id})
  File "/var/runtime/boto3/resources/factory.py", line 520, in do_action
    response = action(self, *args, **kwargs)
  File "/var/runtime/boto3/resources/action.py", line 83, in __call__
    response = getattr(parent.meta.client, operation_name)(**params)
  File "/var/runtime/botocore/client.py", line 316, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/var/runtime/botocore/client.py", line 626, in _make_api_call
    raise error_class(parsed_response, operation_name)
END RequestId: 62f2a2b8-8717-1122-f5ed-19df2268cefb
REPORT RequestId: 62f2a2b8-8717-1122-f5ed-19df2268cefb  Init Duration: 438.03 ms        Duration: 130.15 msBilled Duration: 200 ms  Memory Size: 128 MB     Max Memory Used: 39 MB
Lambda returned empty body!
Invalid API Gateway Response Keys: {'errorType', 'errorMessage', 'stackTrace'} in {'errorType': 'ResourceNotFoundException', 'errorMessage': 'An error occurred (ResourceNotFoundException) when calling the GetItem operation: Requested resource not found', 'stackTrace': ['  File "/var/task/app.py", line 109, in dispatch_request\n    return PATHS[request_path].dispatch(event)\n', '  File "/var/task/app.py", line 26, in dispatch\n    status_code, body = getattr(cls, event[\'httpMethod\'].lower())(event)\n', '  File "/var/task/app.py", line 37, in get\n    response = table.get_item(Key={\'user_id\': user_id})\n', '  File "/var/runtime/boto3/resources/factory.py", line 520, in do_action\n    response = action(self, *args, **kwargs)\n', '  File "/var/runtime/boto3/resources/action.py", line 83, in __call__\n    response = getattr(parent.meta.client, operation_name)(**params)\n', '  File "/var/runtime/botocore/client.py", line 316, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n', '  File "/var/runtime/botocore/client.py", line 626, in _make_api_call\n    raise error_class(parsed_response, operation_name)\n']}
<class 'samcli.local.apigw.local_apigw_service.LambdaResponseParseException'>
2020-04-09 12:17:36 127.0.0.1 - - [09/Apr/2020 12:17:36] "GET /user/kazshima HTTP/1.1" 502 -

@studio3104
Copy link
Contributor Author

Hmm, 自分の手元では普通にどっちも出来るんですけどね、、 #4 (comment)

$ http PUT http://127.0.0.1:3000/user name=JhonDoe
HTTP/1.0 201 CREATED
Content-Length: 66
Content-Type: application/json
Date: Fri, 10 Apr 2020 06:12:29 GMT
Server: Werkzeug/0.16.1 Python/3.7.6

{
    "name": "JhonDoe",
    "user_id": "124fcec4a19f47f2ba3f37df8d3a7e37"
}
$ http http://127.0.0.1:3000/user/124fcec4a19f47f2ba3f37df8d3a7e37
HTTP/1.0 200 OK
Content-Length: 66
Content-Type: application/json
Date: Fri, 10 Apr 2020 06:12:46 GMT
Server: Werkzeug/0.16.1 Python/3.7.6

{
    "name": "JhonDoe",
    "user_id": "124fcec4a19f47f2ba3f37df8d3a7e37"
}

@studio3104
Copy link
Contributor Author

すみませんこれどこをどうやって直したらイケるようになったかもうちっと具体的にコメントいただきたいです! #4 (comment)

@kazfuku
Copy link

kazfuku commented Apr 10, 2020

すみませんこれどこをどうやって直したらイケるようになったかもうちっと具体的にコメントいただきたいです! #4 (comment)

こちらです。

38f9d363f3e3:provisioning kazshima$ diff package2.json package.json 
14c14
<     "@aws-cdk/assert": "1.30.0",
---
>     "@aws-cdk/assert": "1.23.0",
17c17
<     "aws-cdk": "1.30.0",
---
>     "aws-cdk": "1.23.0",
27c27
<     "@aws-cdk/core": "1.30.0",
---
>     "@aws-cdk/core": "1.28.0",

@kazfuku kazfuku removed their assignment Apr 15, 2021
Copy link

@kazfuku kazfuku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

お久しぶりです。お元気でしょうか。

この PR の Review Request が、自分の画面に残り続けるので、Approve しますね。

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants