Amazon web services 如何按区域创建lambda函数
我有压缩文件Amazon web services 如何按区域创建lambda函数,amazon-web-services,aws-lambda,Amazon Web Services,Aws Lambda,我有压缩文件 lambda_function.py包含以下内容 import json def lambda_handler(event, context): print(event) return { 'statusCode': 200, 'body': json.dumps('Success') } 将上面的lambda_function.py转换为function.zip 在执行下面的命令时 aws lambda create-f
lambda_function.py
包含以下内容
import json
def lambda_handler(event, context):
print(event)
return {
'statusCode': 200,
'body': json.dumps('Success')
}
将上面的lambda_function.py转换为function.zip
在执行下面的命令时
aws lambda create-function --function-name sample --zip-file fileb://function.zip --handler lambda_function.lambda_handler --runtime python3.8 --role arn:aws:iam::1111:role/lambda-role
我在一点以下
{
"FunctionName": "sample",
"FunctionArn": "arn:aws:lambda:eu-central-1:1111:function:sample",
"Runtime": "python3.8",
"Role": "arn:aws:iam::1111:role/lambda-role",
"Handler": "index.handler",
"CodeSize": 306,
"Description": "",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2021-04-28T06:47:29.174+0000",
"CodeSha256": "LYco0RgztxYIuoMA=",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "bb285d6",
"State": "Active",
"LastUpdateStatus": "Successful"
}
我的lambda函数位于eu-central-1
我希望我的lambda函数必须在us-east-1
中。这怎么可能
我已使用aws配置更改了“默认区域”,但
在aws创建之后…我得到以下错误
无法连接到终结点URL:https://lambda.eu-east-1.amazonaws.com/2015-03-31/functions“
我是如何配置用户凭据的区域字段的
- 如果您在Linux计算机中,则可能位于
~/.aws/credentials
- 也可以通过
export AWS\u DEFAULT\u REGION=us-east-1
$ cat ~/.aws/credentials # Or could also be via environment variable -> export AWS_DEFAULT_REGION=ap-southeast-1
[myself]
aws_access_key_id = xxxx
aws_secret_access_key = xxxx
region = ap-southeast-1
$ aws lambda --profile=myself create-function --function-name my_first_deploy --zip-file fileb://function.zip --handler lambda_function.lambda_handler --runtime python3.8 --role arn:aws:iam::xxxx:role/xxxx
{
"FunctionName": "my_first_deploy",
"FunctionArn": "arn:aws:lambda:ap-southeast-1:xxxx:function:my_first_deploy",
"Runtime": "python3.8",
"Role": "arn:aws:iam::xxxx:role/xxxx",
"Handler": "lambda_function.lambda_handler",
"CodeSize": 306,
"Description": "",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2021-04-28T07:23:34.828+0000",
"CodeSha256": "xxxx",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "xxxx",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Zip"
}
$ cat ~/.aws/credentials # Or could also be via environment variable -> export AWS_DEFAULT_REGION=us-east-1
[myself]
aws_access_key_id = xxxx
aws_secret_access_key = xxxx
region = us-east-1
$ aws lambda --profile=myself create-function --function-name my_second_deploy --zip-file fileb://function.zip --handler lambda_function.lambda_handler --runtime python3.8 --role arn:aws:iam::xxxx:role/xxxx
{
"FunctionName": "my_second_deploy",
"FunctionArn": "arn:aws:lambda:us-east-1:xxxx:function:my_second_deploy",
"Runtime": "python3.8",
"Role": "arn:aws:iam::xxxx:role/xxxx",
"Handler": "lambda_function.lambda_handler",
"CodeSize": 306,
"Description": "",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2021-04-28T07:29:51.221+0000",
"CodeSha256": "xxxx",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "xxxx",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Zip"
}
第二次运行,使用us-east-1
:
$ cat ~/.aws/credentials # Or could also be via environment variable -> export AWS_DEFAULT_REGION=ap-southeast-1
[myself]
aws_access_key_id = xxxx
aws_secret_access_key = xxxx
region = ap-southeast-1
$ aws lambda --profile=myself create-function --function-name my_first_deploy --zip-file fileb://function.zip --handler lambda_function.lambda_handler --runtime python3.8 --role arn:aws:iam::xxxx:role/xxxx
{
"FunctionName": "my_first_deploy",
"FunctionArn": "arn:aws:lambda:ap-southeast-1:xxxx:function:my_first_deploy",
"Runtime": "python3.8",
"Role": "arn:aws:iam::xxxx:role/xxxx",
"Handler": "lambda_function.lambda_handler",
"CodeSize": 306,
"Description": "",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2021-04-28T07:23:34.828+0000",
"CodeSha256": "xxxx",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "xxxx",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Zip"
}
$ cat ~/.aws/credentials # Or could also be via environment variable -> export AWS_DEFAULT_REGION=us-east-1
[myself]
aws_access_key_id = xxxx
aws_secret_access_key = xxxx
region = us-east-1
$ aws lambda --profile=myself create-function --function-name my_second_deploy --zip-file fileb://function.zip --handler lambda_function.lambda_handler --runtime python3.8 --role arn:aws:iam::xxxx:role/xxxx
{
"FunctionName": "my_second_deploy",
"FunctionArn": "arn:aws:lambda:us-east-1:xxxx:function:my_second_deploy",
"Runtime": "python3.8",
"Role": "arn:aws:iam::xxxx:role/xxxx",
"Handler": "lambda_function.lambda_handler",
"CodeSize": 306,
"Description": "",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2021-04-28T07:29:51.221+0000",
"CodeSha256": "xxxx",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "xxxx",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Zip"
}
我是如何配置用户凭据的区域字段的
- 如果您在Linux计算机中,则可能位于
~/.aws/credentials
- 也可以通过
export AWS\u DEFAULT\u REGION=us-east-1
$ cat ~/.aws/credentials # Or could also be via environment variable -> export AWS_DEFAULT_REGION=ap-southeast-1
[myself]
aws_access_key_id = xxxx
aws_secret_access_key = xxxx
region = ap-southeast-1
$ aws lambda --profile=myself create-function --function-name my_first_deploy --zip-file fileb://function.zip --handler lambda_function.lambda_handler --runtime python3.8 --role arn:aws:iam::xxxx:role/xxxx
{
"FunctionName": "my_first_deploy",
"FunctionArn": "arn:aws:lambda:ap-southeast-1:xxxx:function:my_first_deploy",
"Runtime": "python3.8",
"Role": "arn:aws:iam::xxxx:role/xxxx",
"Handler": "lambda_function.lambda_handler",
"CodeSize": 306,
"Description": "",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2021-04-28T07:23:34.828+0000",
"CodeSha256": "xxxx",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "xxxx",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Zip"
}
$ cat ~/.aws/credentials # Or could also be via environment variable -> export AWS_DEFAULT_REGION=us-east-1
[myself]
aws_access_key_id = xxxx
aws_secret_access_key = xxxx
region = us-east-1
$ aws lambda --profile=myself create-function --function-name my_second_deploy --zip-file fileb://function.zip --handler lambda_function.lambda_handler --runtime python3.8 --role arn:aws:iam::xxxx:role/xxxx
{
"FunctionName": "my_second_deploy",
"FunctionArn": "arn:aws:lambda:us-east-1:xxxx:function:my_second_deploy",
"Runtime": "python3.8",
"Role": "arn:aws:iam::xxxx:role/xxxx",
"Handler": "lambda_function.lambda_handler",
"CodeSize": 306,
"Description": "",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2021-04-28T07:29:51.221+0000",
"CodeSha256": "xxxx",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "xxxx",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Zip"
}
第二次运行,使用us-east-1
:
$ cat ~/.aws/credentials # Or could also be via environment variable -> export AWS_DEFAULT_REGION=ap-southeast-1
[myself]
aws_access_key_id = xxxx
aws_secret_access_key = xxxx
region = ap-southeast-1
$ aws lambda --profile=myself create-function --function-name my_first_deploy --zip-file fileb://function.zip --handler lambda_function.lambda_handler --runtime python3.8 --role arn:aws:iam::xxxx:role/xxxx
{
"FunctionName": "my_first_deploy",
"FunctionArn": "arn:aws:lambda:ap-southeast-1:xxxx:function:my_first_deploy",
"Runtime": "python3.8",
"Role": "arn:aws:iam::xxxx:role/xxxx",
"Handler": "lambda_function.lambda_handler",
"CodeSize": 306,
"Description": "",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2021-04-28T07:23:34.828+0000",
"CodeSha256": "xxxx",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "xxxx",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Zip"
}
$ cat ~/.aws/credentials # Or could also be via environment variable -> export AWS_DEFAULT_REGION=us-east-1
[myself]
aws_access_key_id = xxxx
aws_secret_access_key = xxxx
region = us-east-1
$ aws lambda --profile=myself create-function --function-name my_second_deploy --zip-file fileb://function.zip --handler lambda_function.lambda_handler --runtime python3.8 --role arn:aws:iam::xxxx:role/xxxx
{
"FunctionName": "my_second_deploy",
"FunctionArn": "arn:aws:lambda:us-east-1:xxxx:function:my_second_deploy",
"Runtime": "python3.8",
"Role": "arn:aws:iam::xxxx:role/xxxx",
"Handler": "lambda_function.lambda_handler",
"CodeSize": 306,
"Description": "",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2021-04-28T07:29:51.221+0000",
"CodeSha256": "xxxx",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "xxxx",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Zip"
}
您只需设置正确的区域,就像您使用aws configure或环境变量或参数
--region us-east-1
所做的那样。请提供有关错误的更多详细信息,以便我们可以为您提供更多帮助。您只需设置正确的区域,就像您使用aws configure
或环境变量或参数--region us-east-1
所做的那样。请提供有关错误的更多详细信息,以便我们能为您提供更多帮助。您能回答吗?你能回答吗?