Created
September 16, 2020 20:04
-
-
Save DaisukeNagata/0bf2f8d2ccd88c066d5cab4353974eba to your computer and use it in GitHub Desktop.
SwiftUI_timeCheck by AWS Lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct LoginResModel: Decodable { | |
var statusCode: Int | |
var body: String | |
} | |
private func timeCheck(year: Int, month: Int, day: Int, hour:Int, minute: Int) { | |
urlTimeCheck = "https://7tslpj7nwg.execute-api.ap-northeast-1.amazonaws.com/default/DateTime?year=\(year)&month=\(month)&day=\(day)&hour=\(hour)&minute=\(minute)" | |
let encodeUrlString: String = urlTimeCheck.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "" | |
guard let url = URL(string: encodeUrlString) else { return } | |
var request = URLRequest(url: url) | |
request.addValue("application/json", forHTTPHeaderField: "Content-Type") | |
cancellable = URLSession.shared.dataTaskPublisher(for: request) | |
.map { $0.data } | |
.decode(type: LoginResModel.self, decoder: JSONDecoder()) | |
.receive(on: RunLoop.main) | |
.eraseToAnyPublisher() | |
.sink(receiveCompletion: { completion in | |
switch completion { | |
case .finished: | |
break | |
case .failure(let error): | |
print(error) | |
} | |
}, receiveValue: { login in | |
print(login.body) | |
}) | |
} |
AWS Lambda
import json
import datetime
def lambda_handler(event, context):
year = event['year']
month = event['month']
day = event['day']
hour = event['hour']
minute = event['minute']
dtNow = datetime.datetime.now()
dtTotal = dtNow.year + dtNow.month + dtNow.day + dtNow.hour + dtNow.minute
dtChoice = int(year) + int(month) + int(day) + int(hour) + int(minute)
if dtTotal == dtChoice:
return {
'statusCode': 200,
'body': 'Both'
}
else:
return {
'statusCode': 200,
'body': 'NotBoth'
}
AWS Mapping Template
{
"year": "$input.params('year')",
"month": "$input.params('month')",
"day": "$input.params('day')",
"hour": "$input.params('hour')",
"minute": "$input.params('minute')"
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://twitter.com/dbank0208/status/1305755407688724481?s=20